wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.3 n" u, \( f1 x7 k ?
8 S2 T4 d- z6 n- z8 s: x3 e
2 e1 R! B: z2 r- t4 E1 R
CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))' E/ k k* O) n! k
BEGIN
/ ^- X" p- @! Vset @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);
' j# I8 J% u8 ^; L8 q' |8 kif (@wp_post_id>0) then
: O1 P" U: |9 b P3 q. v0 L set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
Y8 \( g; }$ L1 ?0 i' M if (@term_id=0) then
3 }7 X N0 m, ?" I- P insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);& ]1 \( G6 c; }- _2 i G2 C* D
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);8 A! s! |" B5 j, s, g9 o5 b
end if;
, t4 p; F* l- R5 t9 f8 E 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);
6 }4 d5 [2 ]4 ^ if (@term_taxonomy_id =0) then
% ?, O# L5 X1 m7 o insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);+ h! k7 m( G* d9 K+ m( J2 P( Y
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);' `, C0 H, N5 a# f" ?
end if;# ^7 E) ? M- Q7 ?6 X( u
r: Z2 r7 A. T" J7 M0 _
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then
# g0 h& I! {9 c insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
: Z( S9 }) E( O8 o( t update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
/ }0 O7 U' B) T end if;
. @5 Z0 z7 t! j" P- `% L6 J: eend if;
- Q& p8 F7 r0 y3 E# w, \' WEND4 L/ @% h5 R, Y2 i1 k( f# t
& a$ z& s+ i8 x! H( x# I: q' S3 t% o
調用方法:% O! j; A4 @4 a2 B3 g
, K$ x% O- e* s( S [4 g1 }- Z( v. q
call p_add_article_category('scenery','this is the title about scenery');& p: V0 o5 t2 O$ I
' H0 G, V3 s0 I2 s% k \" L: X+ P
) a5 Z* Z1 m6 {; m |