wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
3 p7 {4 _( O+ \2 b. Q) v$ Z4 K4 m/ N7 \( m* j6 ~
! X1 n& [( T* G/ W- LCREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
% |: J' U. J/ k# Q' QBEGIN
) @# `5 Z) f) _- t' R' Cset @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);
% i1 y3 s( x+ W+ p/ i) N1 x8 y0 Kif (@wp_post_id>0) then9 i J& j7 F9 k7 ^. T& |
set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);, O7 ?+ k7 I: H, f% m
if (@term_id=0) then+ y; D! O1 r7 Z
insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);
+ Y1 ?2 L& D3 T% j" B set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);/ f3 t! F) G& p6 e6 y) A
end if;
- [0 ^) C% f# H 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);4 n* T$ J/ n: n: _) F8 v& B
if (@term_taxonomy_id =0) then5 F W4 J8 j) n& R6 g
insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);' W0 I- Q- ?# u9 L3 H& ]
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);2 |) F9 H3 m% ^' ]' A/ p; ~& ?5 _
end if;+ t% Y- M- T+ L g8 o5 Y' c
8 z/ Z( d0 }) Z' v. w5 h. Q if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then9 A1 V r4 _ {- |* v) Z' z
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
# m9 L* C. M4 F5 t update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
/ ~2 J- ~5 j; }- `! W( z" V end if;: T3 \9 v6 P; ^. ?, {, {1 h
end if;1 v4 d/ Z# f5 y$ s( u3 ]/ M
END
$ E, r% \0 j& u3 F7 e8 K. ]" t3 s: {% W
調用方法:2 x8 Q8 N* y6 V$ }
6 ?( F/ r% K3 ~; h4 b/ w0 e- u
call p_add_article_category('scenery','this is the title about scenery');6 K$ O7 O U+ S% J4 T! Y
6 R! @' j( i0 s: r! j2 _! A6 h1 w0 g+ O* E7 Y Z
|