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.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
I 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 etc. This would be much much faster/reliable/simpler.