wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
3 ~7 s+ B! V. ?$ e- s( f
4 T9 M$ P5 ]: B2 n9 O
, J! A S' K' l# UCREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))+ d! O6 c' P/ R2 {) B: A, P
BEGIN& \5 U/ K* a1 @. _3 L
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);4 @- w4 ~ R, n5 }
if (@wp_post_id>0) then
4 H0 n* X) ^1 t. t6 A/ j set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);7 l( f5 H$ L# v. w, t
if (@term_id=0) then& H7 d: @, G' } {- U; T! i
insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);. }+ s" X) Z7 ]( p
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);
. c6 d7 [$ M$ M/ l end if;
6 {3 ]& v6 H' g! k 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);& [" ^' g0 j* `; v N
if (@term_taxonomy_id =0) then
# G4 }; P, x; Z4 U insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);2 `7 a4 ~6 u- O+ q
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
) @. y# H; \7 i8 c# z: d& e6 J end if;- @2 ~* @; y0 {# U9 m5 D1 ]6 b
7 t5 d* E, [8 N) x/ Y
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then
& f0 N* ~6 L4 Z4 i1 } insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);$ m) g. I: O! I8 R* Y
update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
# T" D0 _2 A6 i; L2 z0 ? end if;& `* k3 }% q; g! N
end if;
$ a: b/ J9 A9 E3 ^ z$ j5 i @END+ ^ O/ w1 [/ p7 _' @+ T) ~
( i4 u0 q& Z/ @. _( c9 e% f調用方法:& [7 \6 q6 n/ E4 i& O) U, @
/ y' R2 o# h9 B& ]; Q; U$ m) F
call p_add_article_category('scenery','this is the title about scenery');
! K% D$ P- @- C
% E \- q$ e8 D+ X N3 P. V9 S; O: F$ V' {
|