Support » Fixing WordPress » Remove Category from Converted Custom Post Type

  • Resolved ZeroGravity


    I converted some posts to a custom post type using Post Type Switcher. Worked beautifully. This custom post type doesn’t use the standard categories. The only thing is they are still showing as being assigned to the standard categories they were part of. The number of posts under Posts -> Categories still indicates they have a standard category assigned.

    When I create a new post under the custom post type the default standard category is not assigned. How can I remove the category from the converted posts?


Viewing 5 replies - 1 through 5 (of 5 total)
  • Try running this SQL query from phpmyadmin. Please backup the entire database before you attempt to run this.

    delete r from wp_term_relationships r
    inner join wp_posts p
    post_type = "custom_post_type"
    and p.ID = r.object_id

    The above is assuming the table prefix is wp_. If it’s something else, just rename the tables.

    Replace “custom_post_type” with the actual custom post type name.

    Thanks Rajesh. I added a check for the category I wanted to delete (and keep the assigned custom taxonomies) and it worked.

    DELETE r
    FROM wp_term_relationships r
    INNER JOIN wp_posts p
    ON p.ID = r.object_id
    WHERE post_type = "custom_post_type"
    AND r.term_taxonomy_id = 4

    Even though the records were deleted the count was still the same. I noticed there is a count column in wp_term_taxonomy. Does WordPress update this or will I need to update it manually?

    Sure it’s safe to reset the count column in the wp_term_taxonomy table for that category.

    Thanks. I will do that since I know how many there are. If I have issues or if there is a next time where there are more posts than I would like to count I just stumbled across the wp_update_term_count function.

    Thanks Again!

    You’re welcome. Glad I could be of help.


Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove Category from Converted Custom Post Type’ is closed to new replies.