wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.& X+ x* i* P, W
+ x% ?0 L6 M+ K$ M
% j0 Z; G! B7 {" b \8 `CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))6 F: {" u% K, L6 @; m3 }
BEGIN/ C. D$ N6 I; o8 g9 C
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);8 d3 }8 p& E4 e% h* y
if (@wp_post_id>0) then
" m4 F2 h7 ]: R# o) X# j" {( ` set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);5 ]2 \; F& z, d% @# v
if (@term_id=0) then
$ [" c" {: _1 M, q) N insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);
" h0 D2 W0 r6 x2 e5 l set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);
j/ x5 j1 j/ m I& Z5 F& q& j end if;
, {! `& x0 N( o 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);2 t/ f3 I" M: Y) R1 A
if (@term_taxonomy_id =0) then' Q! _3 g: x2 X( m
insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);
; m H" y( _7 X; u" D9 S$ ^& S set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
# v6 ~0 W- y2 O/ e6 ^1 @; k- w end if;
* Q# Y; B( f: g
) r0 }" |6 a F& k* F; ^" z0 f if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then: J) }+ T; P6 ^5 [: d+ O! Q, Z
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);" P3 |2 ?, e1 q, k/ O
update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
* a9 A( x8 i2 R/ r$ a0 U$ C end if;
7 G% ?1 L0 |3 Xend if;) R: T3 ?& k7 \7 T$ f2 d
END
( `+ i$ j) @1 a3 ]" Y$ P# s9 w t6 e" x d5 M; q4 m
調用方法:& D2 G4 U8 p! {* T
) y$ C# T& O6 ]7 Z+ _* tcall p_add_article_category('scenery','this is the title about scenery');# l5 C) @; O) Y8 q) P
4 C" T' G; t/ n! l+ x/ c( D( S4 d K2 X
|