admin管理员组文章数量:1430551
I am trying to migrate all contents from a category to another using SQL. Thanks for help.
I want to change the term_taxonomy_id of this query.
I am trying to migrate all contents from a category to another using SQL. Thanks for help.
I want to change the term_taxonomy_id of this query.
Share Improve this question edited May 2, 2019 at 14:00 Tweak asked May 2, 2019 at 12:41 TweakTweak 311 silver badge8 bronze badges 10- What's the reasoning behind doing it in SQL? Would it not be faster to just rename 2018 to 2017 instead of moving each post? Then you'd only have to create 1 term for the latest year and one for the oldest year – Tom J Nowell ♦ Commented May 2, 2019 at 13:02
- Also, is there a particular reason this isn't being done via WP CLI? – Tom J Nowell ♦ Commented May 2, 2019 at 13:03
- Thanks for your answer @TomJNowell , the reason is that i have many posts from 2008 to today. I want to create a script to archive each of these posts to the corresponding year. – Tweak Commented May 2, 2019 at 13:05
- My query give me a line, for example. How can i change corresponding attributs of this line which is the result of my query "SELECT * ..." ? – Tweak Commented May 2, 2019 at 13:07
- 1 I have edited my post, maybe it's better for the comprehension now. – Tweak Commented May 2, 2019 at 13:53
1 Answer
Reset to default 1I strongly suspect the reason you want SQL that you haven't mentioned/shared, is because you can't use the WP functions to fetch the posts and do it manually in a single request due to the PHP time execution limit, or you don't know how to.
Sadly, doing it via SQL is no guarantee this will work, additionally, you'll break all the caches involved, all the term post counts will be broken, and a few other things too.
The best way to do this, is with WP CLI, for example here we take all posts in category X, put them in category Y, then remove them from X:
# get all the post IDs in category x
posts=wp post list --category_name="x" --field="ID"
# Move them from x to Y
for id in $posts
do
wp post term remove $id cat "x" --by="slug"
wp post term add $id cat "y" --by="slug"
done
But given you've hinted you're actually doing this by year, it might be easier to simply rename the terms, so 2010
-> 2009
, 2011
-> 2010
etc. This would be much much faster/reliable/simpler.
本文标签: wp queryMigrate posts from category and subcategory via SQL
版权声明:本文标题:wp query - Migrate posts from category and sub-category via SQL 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745531640a2662088.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论