wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
/ t- T9 H4 Z' p, _2 V" o
& V) d1 m' M4 y d0 A5 x% B% \) |1 w1 C1 y r4 K5 q$ k
CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
7 L) ?3 ~+ b N% YBEGIN& K) Z( t) d) D1 v( l3 i& i
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);# _- F8 N3 G l5 Q) D k& s
if (@wp_post_id>0) then
0 t3 V# b) O4 `# T' c7 { set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
& M- B% e- L, ~8 i- g0 k if (@term_id=0) then
$ w2 o0 ]/ ~" V3 s# { insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);
- H2 i: u# s0 y1 H; \! N& [( H set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);8 A! X+ [' a$ i1 r
end if;7 v0 Q! h% S# L2 y5 K9 d
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);- L# ^8 O. s* p0 f `
if (@term_taxonomy_id =0) then
8 y$ S- K6 g5 }% l, E8 i/ g insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);; Q7 m1 O! E+ g2 M9 F* S# m
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
6 a2 ?5 ^0 B: f1 R% b6 j) h+ W/ R end if;
6 W& O! E0 j% t
7 x4 f& P8 i& r( ]) U4 n if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then' y! O- r' u/ |! [2 x
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
* V) Z; y* l& M% `& S: e0 x update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
& ^% k4 F" M( f/ s. i4 S) g, y/ i end if;
! t g5 [) q l1 q- X W6 send if;
+ Y, \5 T8 @3 R- P3 z# c' nEND& S8 o- s: J0 x2 ~2 g$ N" S
- g$ u' T& ^8 I, L! g) C3 K/ f6 g調用方法:6 k6 l2 U3 f5 ]; \( _0 D" A1 `
# e0 r6 w5 K( ccall p_add_article_category('scenery','this is the title about scenery');
7 n+ F- w. V. q
" r) ~3 Z- J3 {1 m1 n
0 E" e' P. c0 I3 ^5 ^# p* I |