wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.; b# G7 G' s+ l' \0 K$ F5 E2 t
. A6 V+ a$ V% m, ]
5 F" y4 S$ w8 N9 _% N3 Z: ECREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
/ v, V9 L# f+ B# ^BEGIN
3 B0 I9 r2 l4 B! wset @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);
7 B0 L* a6 G# x6 @8 x' D% f; D% Dif (@wp_post_id>0) then$ u1 Y' B# `+ _0 Y
set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
5 Q! @) |3 I, P6 v& q if (@term_id=0) then3 O7 D( s1 R# M O, m, r, W
insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);
; x' d4 z; S+ [$ n! i set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);; n6 C6 L# Z/ I* p- Z& ~
end if;' p! f& T9 [* N4 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);/ z) F) k4 x2 N0 F3 Y
if (@term_taxonomy_id =0) then
) ]. w# ^* y) T9 h1 n# a L# S insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);; W) q1 @: G* q: t& }. Q, ?8 C7 |7 \
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
3 L% x( U8 U/ F7 G" p+ M end if;! @- H% u; l0 p# V* ?7 m
7 n" \" X6 m; u8 n. @ if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then
, l* i1 s0 U' M/ d* B# e/ D& s insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
- P! U7 {/ K0 g1 e: S# ] update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;$ O% V& @# |& D1 P- ?
end if;8 F3 N$ L& @4 @/ D0 n
end if;
+ [- W3 g, F! J% `+ n$ D CEND
/ q0 E! I E9 m6 t; Z2 i
9 E7 Y/ K* ^* R. O6 ^調用方法:
! t: C q3 Z+ }, P( |2 x- Z; ?4 x, [( Z+ o; ~9 j9 O6 K
call p_add_article_category('scenery','this is the title about scenery');
) u( m/ R; Z# z
+ Z, S$ O5 W/ J+ Q# X, c3 j# R) o5 x
|