|
wordpress在线写英文有些慢,我是在本地写了一个简单的录入系统.写好后批量导入进去.这牵涉到一些category或者tag的导入.为了批量导入.写了一个存储过程.然后批量调用存储过程,可以把category导入进去.分享一下.
CREATE PROCEDURE `p_add_article_category`(in v_term VARCHAR(300),in v_title varchar(2000))
BEGIN
set @wp_post_id=IFNULL((select id from wp_posts where post_title=v_title limit 0,1),0);
if (@wp_post_id>0) then
set @term_id=IFNULL((select term_id from wp_terms where name=v_term limit 0,1),0);
if (@term_id=0) then
insert into wp_terms(name,slug, term_group) values(v_term,v_term,0);
set @term_id=(select term_id from wp_terms where name=v_term limit 0,1);
end if;
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);
if (@term_taxonomy_id =0) then
insert into wp_term_taxonomy(term_id,taxonomy,description,parent,count) values(@term_id,'category','',0,0);
set @term_taxonomy_id=(select term_taxonomy_id from wp_term_taxonomy where taxonomy='category' and term_id=@term_id limit 0,1);
end if;
if(not EXISTS(select 1 from wp_term_relationships where object_id=@wp_post_id and term_taxonomy_id=@term_taxonomy_id)) then
insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values(@wp_post_id,@term_taxonomy_id,0);
update wp_term_taxonomy set count=count+1 where taxonomy='category' and term_id=@term_id;
end if;
end if;
END
调用方法:
call p_add_article_category('scenery','this is the title about scenery');
|
评分
-
查看全部评分
|