wordpress批量更新category的方法

  [复制链接]
查看: 636   回复: 7
发表于 2013-7-9 10:58:26 | 显示全部楼层 |阅读模式
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');


评分

参与人数 2T币 +4 收起 理由
月光飞燕 + 3
sophieqd + 1

查看全部评分

发表于 2013-7-9 11:19:57 | 显示全部楼层
火车必用,谢谢分享。好东西
回复 支持 反对

使用道具 举报

发表于 2013-7-9 21:11:13 | 显示全部楼层
好东西,谢谢分享!爱疯!
回复 支持 反对

使用道具 举报

发表于 2013-7-10 02:41:54 | 显示全部楼层
能详细说下怎么用吗?
我是不是建一个php文件,把这个句子写进去
比如
call  p_add_article_category('scenery','this is the title about scenery');
call  p_add_article_category('scenery','this is the title about scenery 2');
call  p_add_article_category('scenery','this is the title about scenery 3');
这样是添加3个文章到目录了.
如果一次改n条,是不是就要写n条.
可以用关键字匹配分类吗,比如标题有scenery的都一次分类到scenery去
回复 支持 反对

使用道具 举报

发表于 2013-7-10 10:00:03 | 显示全部楼层
还在搞自动阿,太佩服了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-7-11 08:58:33 | 显示全部楼层
有鱼不换酒 发表于 2013-7-10 02:41 wordpress批量更新category的方法
能详细说下怎么用吗?
我是不是建一个php文件,把这个句子写进去
比如

先把存储过程通过phpmyadmin注册进去,然后批量调用就行了.一次可以弄几千个.一下执行.

回复 支持 反对

使用道具 举报

发表于 2013-7-11 16:03:57 | 显示全部楼层
shanguiyao 发表于 2013-7-11 08:58 wordpress批量更新category的方法
先把存储过程通过phpmyadmin注册进去,然后批量调用就行了.一次可以弄几千个.一下执行.

...

每一个post的标题都是不一样的呀.这样不是要为每一个post文章调用一次你这个存储过程吗?
批量调用一次,不所有包含某个关键字标题的文章都添加一个分类去.这样如何实现呢
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-7-11 20:20:41 | 显示全部楼层
对,每一个post标题调用一次.可以批量生成的吧?写个sql都拼出来要执行的一堆存储过程语句了.应该不太难吧.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则