wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.% C" y$ L" z) s ^: W
" g) i8 \2 p% W) j- s. k+ S/ J% ~, \- D1 }4 T' m% D
CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))1 `: N3 W3 q, P
BEGIN: j1 B1 H: w" D
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);3 p# k2 K) a4 w9 U* R7 ]7 n; B
if (@wp_post_id>0) then( M8 V2 W" S4 o' L# Y" s
set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);' j: w* N" Z3 v9 s1 n+ I! _! o
if (@term_id=0) then- U) T* R3 r+ f9 r
insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);
; e- x" k6 o; O set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);) U' `9 L. O7 K$ M
end if;& a6 e2 a7 O6 L4 ]( l) P
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);0 w1 g4 J7 E/ m3 n* U- t
if (@term_taxonomy_id =0) then7 _) y& y! a) o. B
insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);
9 Z3 V, Z% w0 X set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);$ z8 t* P- g# f9 L& P% ]6 j& `# K: L
end if;6 c8 _4 v8 k* `* ~
7 |& z9 V, n7 z+ w3 o. p" y
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then, S/ R5 b2 e: J
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);3 B1 O% t& L' \+ L' R& I
update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;4 a4 C$ m% r- k/ {9 z8 {
end if;
_: M- S1 D1 j; Dend if;
6 @. J3 M5 @' X2 {! zEND; o5 k0 Q2 M" w6 }% Y" \
I9 D8 e9 R1 A
調用方法:' G4 e6 F- o5 E
; `; V. y4 X( c, g: Kcall p_add_article_category('scenery','this is the title about scenery');: \3 W8 |, c# F9 y$ r
# a& S, O! A9 v5 F u9 E
8 E4 @" H* b6 N: T9 B; D |