wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.# Z$ z5 _8 k8 ]0 u `
& M T R V* Z# C4 g. k4 n0 F' K' w8 X0 \- L
CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))+ c, `* u2 ~- b' Y; `: C( {
BEGIN
# g: W- Z( D: P- iset @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);6 F7 Z" C% J: O" _
if (@wp_post_id>0) then
# Q, n! b# y1 m7 E% e set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
2 N2 y. x3 @0 ?: I# l if (@term_id=0) then
4 \) k" p8 Y1 X2 N9 j- x7 G# { insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);1 I- `1 e3 b3 S0 u1 Y( |
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);% p2 }2 d' I7 n" f: X
end if;9 `# F( W( o) G: d$ N% z
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);
, g( M( e, q6 C" f( { if (@term_taxonomy_id =0) then
3 \( U! P' l( @, ]1 V: o6 x% A5 ~ insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);
! D! h# P, X$ |" {/ Y% J& ` set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
4 b7 ?0 A/ d. \9 }: `: }* b end if;- H$ J/ t/ o8 H2 I/ d l& X
' M( D- V x4 O$ V6 L9 d5 q+ {
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then5 O5 n% ?' q0 u$ A* T2 J9 F' y
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
3 O6 ? {+ T/ i0 @ update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;6 b7 m; Y; P/ U$ E! ~' \2 P
end if;2 B& I# S- [ j; _6 {) t9 t2 B
end if;
, ]5 H) W( ?7 V2 O* i& Y6 ]END A) o" B6 V9 @. ?3 Q
: Q; C" c$ I. z9 x1 h, ?0 [6 N! d% r
調用方法:
x9 Q8 i" E0 `5 c$ P* R1 N$ m- S X M4 s
call p_add_article_category('scenery','this is the title about scenery');% m" b, `; b$ `2 H; }1 }: y
8 V: N& x4 h* `3 S- {: P* A
& A& \3 p) O1 _6 Z$ i8 C4 s
|