dongming6201 2017-07-14 12:57
浏览 53
已采纳

如何更新现有自定义帖子类型的类别?

I am picking up work on a legacy tool and am redoing a page that works with custom post types. The new post type we'll call new_resource, and has the same "category" identifiers as the existing legacy resource type, old_resource. I'm pretty new to Wordpress, so there may have been a better way of doing that than just starting from scratch, but this is where I'm at. My goal is to use the same data that the existing resources used, so I don't have to create all of the new posts.

I ran two queries that updated the existing resource types to the new one:

update wp_posts set post_type = 'new_resource' where post_type = 'old_resource';

and

update wp_posts set guid = replace(guid, 'old-resource', 'new-resource');

All of that is working.

What I want to do now is update the custom taxonomy (I'm not using the default categories built in). We'll call it resource-category for the example. The existing old-resource posts all had their resource-category assigned, and when I query wp_terms, I can see all of the categories. I've set up those SAME categories in the new-resource type. Is there a query that I can run that will select all of the resources with a type of new-resources (all of them are now, after I ran that update query above), and set their categories? Like update their term_id where the term_id is still pointing to an ID of the old category type?

Wordpress Version: 4.2.2 PHP Version: 5.3.3

Edit:

I ran this query:

mysql> select term_id, name, slug from wp_terms where slug = 'videos';

+---------+--------+--------+
| term_id | name   | slug   |
+---------+--------+--------+
|      69 | Videos | videos |
|     177 | Videos | videos |
+---------+--------+--------+
2 rows in set (0.00 sec)

The term_id 69 belongs to the old resource type. The term_id 177 belongs to the new resource. I want all of my current resources (the ones I already ran the update resource type query on) to point to term_id 177 instead of 69, but I'm not sure of the relationship between posts and terms.

Something like update the term_id for all new-resources, set 69 to 177.

  • 写回答

2条回答 默认 最新

  • doushen4719 2017-07-14 13:33
    关注

    The update set only the column in set clause .. and i set clause ypu can have more than a column

    You could do the two update using an update only

     update wp_posts 
             set post_type = 'new_resource', 
             guid = replace(guid, 'old-resource', 'new-resource')
     where post_type = 'old_resource';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改