wordpress在線寫英文有些慢,我是在本地寫了一個簡單的錄入系統.寫好後批量導入進去.這牽涉到一些category或者tag的導入.為了批量導入.寫了一個存儲過程.然後批量調用存儲過程,可以把category導入進去.分享一下.
, m: i' s3 D6 @$ x; X4 g5 R# m' K4 a* y
' w& u4 m8 B7 P, F* a
CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
- w3 g% E n. d" X! Y& P% t; JBEGIN, w# R. c: V+ t) a
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);
. ^9 E4 l0 L4 s3 Zif (@wp_post_id>0) then
( F. D8 c, o" J set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
3 o9 |9 F1 g: H if (@term_id=0) then
9 I& H, z' v) b6 v7 [ insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);9 r& |9 u9 x* u# v# H8 s5 u: M
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);
/ |/ U/ _( O2 H end if;" b! p: {9 |" h
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);1 k$ U: v/ b9 a( c3 M/ l
if (@term_taxonomy_id =0) then+ ]) V( h, M5 ?
insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);
3 A( ]- w" G. p. m% N6 h set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
5 _; y2 b- {# O4 w8 @ H8 X end if;
/ @9 ?3 Y( _$ |9 Y/ f7 Y& t( N$ ~8 H! o- }
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then( o( j( Y3 e; F6 Q) i* }( K
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);# V9 ]# q: k S6 Q$ {8 G. v1 j
update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
* l! Z8 ~; o; g! e* Z6 D end if;
9 {" E. j k' ^" t. x. K @end if;
/ N' u7 a3 P$ s! p9 _: C7 yEND% G5 K& O+ @9 M2 b3 u0 f o) g
5 m, N; d0 P E: j! F調用方法:4 a# t! b& X, L" P2 {( Q, D
4 r( l0 D" f' s) B B9 `9 H
call p_add_article_category('scenery','this is the title about scenery');
' z7 \; X4 w( z' }2 f2 K2 G% H4 ]
/ w0 J8 M8 a) `! A8 J/ m1 j
|