wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
4 s3 g) b$ l' o" n8 R- p
# \0 t7 a' K; w2 n% y0 @3 e8 J2 D: w+ z5 a2 \& [
CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
+ e( g k4 M \+ K( h4 ABEGIN" s% Z: z9 O) }: c
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);
- ?. C& d4 P( o4 v+ O/ @if (@wp_post_id>0) then
- \1 x, C' ?# o$ b4 `$ J1 e set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
8 ?* z1 X% T& A3 a if (@term_id=0) then+ m7 I0 f5 e4 S4 Q' i& q; g$ |
insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);
! E1 V* u. c" ]2 U" r set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);
! Q$ `9 U3 k9 L# o+ X end if;
$ A. |, E. a7 j4 n 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 e" f F6 m) h4 ], i B8 A if (@term_taxonomy_id =0) then0 E' P$ C+ N0 F, \, i7 v2 { U$ U* Q
insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);. c& I0 m" n- V6 s5 U
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
' Y. ]9 c9 v5 a5 A- p0 ~6 ` end if;
5 J% [3 z! y# o7 Z
/ Q- @3 Q0 b9 M9 B* h- D if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then
+ B. c9 @7 I" P( b8 b8 J insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
& Z" R# {( h& Y update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
% X' C( A3 r E, U) q0 l8 l; Q. D end if;$ w. M& J3 @( o. k# U1 L( j* f
end if;4 l$ b7 l3 q8 w1 H4 l* Q2 B
END: c4 b- ~) A! e0 j% c
; F* {( r; u* s, U6 _8 a/ @
調用方法:$ G! c3 n# y: a/ o8 Q. {" }
8 V8 v" Q1 Q- r) Q2 X
call p_add_article_category('scenery','this is the title about scenery');
0 x2 F8 m. s+ b0 J3 f! M b
% N# {; F# y# X% |: }% ^. {! p7 _' m# R. D; ^ p
|