wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
+ f/ v/ {3 r4 F5 Q$ I; R
( u3 c/ a9 G! ?3 K( \1 B# Y
6 n- a3 X) R' o% `' _6 KCREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))# s9 e( D! P/ X0 i9 V
BEGIN6 N& O9 L# {; J; v) e
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);# b2 T5 C: V: t2 ]! u) D {# K$ i+ U
if (@wp_post_id>0) then
4 I8 p0 A" z, u' H7 I set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);$ S, @. n! s( }9 U0 `7 T
if (@term_id=0) then4 ]# m1 b7 C; |; T
insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);, o# v5 k; f: E. e3 y
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);$ D3 _2 H1 P+ e8 }
end if;
# l6 a2 u( o/ Q set @term_taxonomy_id=IFNULL((select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1),0);
% G' Z5 h7 |6 T" T5 E" s; F1 P- c if (@term_taxonomy_id =0) then
+ q! Q; x; j1 N. H) ]; s" g' k6 B insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);
( d1 W. u/ {8 S7 R7 G/ f4 Z" { set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
: k- u/ v2 S. |1 K1 W end if;
5 R& h, \5 X( I0 u" i) x4 V! G
% l; t; j ?+ c if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then
3 o9 U% Y" p% a9 l insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
# p1 d/ v( T% e1 D) n9 e* P% P update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
8 q1 l6 G5 z3 R0 B+ l5 W end if;
; \3 h X6 W G8 I8 T9 L% lend if;
# i4 i9 l6 W7 S3 Y- DEND
1 u1 V7 V' U/ r8 B# y l: W9 I
- v* ]; | t( Q. B6 G# M5 p Z. r調用方法:
2 \+ ]& ^$ ^) t8 A8 l2 x) E3 k4 M# ]5 J% _9 h; u
call p_add_article_category('scenery','this is the title about scenery');0 p: k' Y ~, u2 _& h
. n) i- G6 n/ X- I* y3 O; |+ ^, g e+ j, X
|