WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Remove Category from Converted Custom Post Type (6 posts)

  1. ZeroGravity
    Member
    Posted 1 year ago #

    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?

    Thanks.

  2. Rajesh Soni
    Member
    Posted 1 year ago #

    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
    WHERE
    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.

  3. ZeroGravity
    Member
    Posted 1 year ago #

    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?

  4. Rajesh Soni
    Member
    Posted 1 year ago #

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

  5. ZeroGravity
    Member
    Posted 1 year ago #

    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!

  6. Rajesh Soni
    Member
    Posted 1 year ago #

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

    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic