wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
* g8 N+ } ~2 x; W* L; U
6 x+ ?8 e/ p& y4 Y# J
" F: w- e7 ?( c$ x) g! kCREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
$ L8 [7 I: I u1 e3 Q- h0 t3 t3 cBEGIN/ ?/ Z# b7 ?, P6 G9 a* ]4 s
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);) o1 N4 W" n, V4 ?- [, K) i9 H
if (@wp_post_id>0) then
/ J; o, ~% G- r set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
5 l \2 F( o1 e, m& S& e* N% f1 y- } if (@term_id=0) then
! x: c, Z3 X9 w4 b& f$ ~ insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);6 M6 i( @# ?; A% E
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);" i. ^$ u6 Y" {- t" M0 Q$ m
end if;
! X, S: s! z+ Y4 @# K% Q7 | f 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);
) [) ?1 i1 F$ m5 A# j1 @ if (@term_taxonomy_id =0) then1 a# h$ ]+ K, B
insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);0 r5 P& A/ u) e3 u/ @: r( ^
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
; w* P d7 K) Q8 O end if;8 j+ f; N1 d3 q' T+ u& n1 e7 u K
/ F0 `$ ], R5 f6 t8 A/ ~& I7 w0 }+ C
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then( ]4 R# J( D" i* Y6 J
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
1 m; E8 }1 c |8 _) k' J6 K: U update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;8 Q+ ?- o1 u1 g/ R
end if;: Z6 @ K& {, {4 N
end if;
, g- z2 ]4 q) ]6 ]9 T- BEND
d d" M- ?) M3 O' ?
; t6 `6 K2 P- L0 t w2 O0 Y2 X: M調用方法:0 L R* R: t0 H4 W* x
" D1 [: O4 c* c% | i7 P
call p_add_article_category('scenery','this is the title about scenery');
, `' O8 ^/ s$ H( S( o5 W1 f) v, k! N2 V) u( }9 v
) ]$ s9 u; u+ M0 Q. B
|