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条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog