wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
3 ?% D& q0 V4 {' W0 Z* k/ M% F5 \6 d8 \7 g% l
7 ~' a: o$ ]6 y: y* ECREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
. k# D! b* ~$ _* g+ v! d _BEGIN7 m0 y, p w/ s; q U4 L! `
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);
0 h9 g# `& E/ o6 n/ s& Vif (@wp_post_id>0) then
+ Q5 u3 V. H; u( E! t set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);4 b1 d3 H% {9 d7 J
if (@term_id=0) then
8 V( F* U$ W: H U# A3 C insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);+ E! d, @/ I( t* ^) W" B" |
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);+ k3 v' J# k+ w6 \% A, d, q
end if;$ o- i) W( k4 _- {) Z6 _; X& p
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);. r: B4 Q8 V2 K3 H2 `$ U# O2 Z# a/ ~
if (@term_taxonomy_id =0) then
0 O9 N# q6 A; I3 l) p' \ insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);
3 Z- c0 G7 e0 }, Q: w6 e set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);7 h4 _, p+ C, |
end if;
, U- m4 V0 ^4 X+ d. ^4 _( d. k2 s2 Z/ d3 d1 U" C
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then
$ y& _2 _! Q* q- Y: b insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);4 z+ V/ N' P6 J* O
update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
S3 \# i, O# `& o c end if;/ m7 ?3 _5 B" d4 a& B& G
end if;
+ W1 E9 X! b7 i* U; B! {/ xEND& ~7 k, W& F# z' m
9 s& j$ z9 k6 G4 x. ] t" A
調用方法:9 E3 u! i7 s+ q+ D' G. b' B
, ~; z, `% X) m7 Y0 D" gcall p_add_article_category('scenery','this is the title about scenery');
0 v, g7 N3 g/ m
+ ^8 i: L: I% K2 R
- q: Z! G; U z |