Support » Fixing WordPress » Need to bulk remove categories from certain posts

  • I decided I wanted to add a new category instead of using a tag for that information on my site. I used the Tag to Category conversion option built into WordPress and now have that category. However, the default category is still associated with those posts (roughly 500 posts).

    Is there a way that I can bulk remove the default category from all of these posts without removing the new category I just created? I only want one category per post, so removing the default category is needed. I can do it by Quick Edit on each post, but that’s going to take a long time.

    Thanks,
    Matt

Viewing 1 replies (of 1 total)
  • Is the default category used on any other posts? If not, just delete the category.

    If you need to only delete posts that have both categories, you can use a 4 step SQL process.

    Assume the id of the old category is 32, and the new one is 89 for this example.

    BACK UP THE DATABASE FIRST!!

    Next, create a temporary table with the rows from wp_term_relationships that have the new category:

    CREATE TABLE temp_relationships
    SELECT * FROM wp_term_relationships
    WHERE term_taxonomy_id = 89

    Then, delete the term_relationships rows that have the old term_taxonomy_id that are also in the temp_relationships table:

    DELETE
    FROM wp_term_relationships
    WHERE term_taxonomy_id = 32
    AND object_id IN (SELECT object_id FROM temp_relationships)

    Finally, drop the temp_relationships table:

    ‘DROP TABLE temp_relationships’

Viewing 1 replies (of 1 total)
  • The topic ‘Need to bulk remove categories from certain posts’ is closed to new replies.