I used database to empty wp_postmeta, wp_terms, wp_term_relationship, wp_term_taxonomy.

And I have post content of about 50k. I just created a new category in wp, is there any way to assign all the whole 50k post to the new category I created at once?

  1. Find out the ID of the category that you want to assign. You'll see it in the URL when editing the category (URL will be something like ?taxonomy=category&tag_ID=3&post_type=post, here 3 is the ID)

  2. Assuming that the ID is 3, you can now run this query in your database (eg via PHPMyAdmin)

    INSERT IGNORE INTO wp_term_relationships
    (object_id, term_taxonomy_id)
       FROM wp_posts
       WHERE post_type = 'post' AND post_status = 'publish'

If you use a different prefix than wp_, be sure to change it. Also change the 3 to the ID you want.

  • 1
    Why do you use LIKE instead = here: post_type LIKE 'post', post_status LIKE 'publish'? – nmr Aug 10 '18 at 9:53
  • @nmr I thought LIKE is a cleaner way to compare strings. But = seems to be faster and since I'm not using wildcards, I changed it to =, good catch – kero Aug 10 '18 at 10:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.