How to Completely Remove Custom Post Types and Taxonomies from Your WordPress Database
Content
If you've used the Custom Post Type UI plugin to create and manage custom content types, you may have encountered a common situation: you delete a post type or taxonomy, but traces of it remain in your WordPress installation. This can manifest as lingering rewrite rules, menu items, or data visible in other plugins.
This guide will explain why this happens and provide safe, effective methods for cleaning up your database completely.
Why Deleted CPTs and Taxonomies Leave Traces Behind
The fundamental principle to understand is that the Custom Post Type UI plugin is a registration tool, not a content management system. Its primary job is to tell WordPress about your custom post types and taxonomies. When you delete a content type from the CPTUI interface, you are only deleting its registration settings, not the content created under it.
This design is intentional. The Custom Post Type UI team has stated they "pride ourselves on making it easy to leave CPTUI... without much hassle." By not automatically deleting your content, they prevent accidental, irreversible data loss if you change your mind or are moving the registration code elsewhere.
Consequently, the following elements often remain after deletion:
- Posts and Terms: All posts belonging to the deleted CPT and all terms within the deleted taxonomy remain in the
wp_postsandwp_termstables. - Rewrite Rules: The configuration for the post type's URL structure often persists in the
wp_optionstable under therewrite_rulesoption, which autoloads on every page. - Plugin Settings: The definitions for your post types and taxonomies are stored in the
wp_optionstable ascptui_post_typesandcptui_taxonomies. - Associations in Other Plugins: If other plugins (like Advanced Custom Fields or Admin Menu Editor) were configured to use your CPT, they may still reference it, causing it to appear in menus or lists.
Step-by-Step Guide to a Complete Cleanup
Warning: Always create a full backup of your WordPress database before performing any manual cleanup operations.
Step 1: Delete All Associated Content
Before removing the post type itself, you must delete all of its content to prevent orphaned posts.
- Go to your WordPress admin dashboard.
- Navigate to the screen for your custom post type (e.g., "My Projects").
- Bulk-select all items and move them to Trash, then empty the Trash.
- For custom taxonomies, you must also delete all terms. You may need to temporarily re-register the taxonomy in CPTUI to access the term list and delete them before proceeding.
Step 2: Delete the Post Type or Taxonomy in CPTUI
Once all content is removed, you can safely delete the post type or taxonomy from the Custom Post Type UI > Post Types or Taxonomies menu.
Step 3: Flush Rewrite Rules
This is a crucial step to clear out the old URL rules from the database. Visit Settings > Permalinks in your WordPress admin and simply click "Save Changes" without making any modifications. This refreshes the rewrite rules and should remove references to deleted content types.
Step 4: Manual Database Cleanup (Advanced)
If traces remain, you may need to manually remove option values. This should only be done if you are comfortable using phpMyAdmin or a similar database management tool.
- Access your database via phpMyAdmin.
- Find the
wp_optionstable. - Locate and delete the rows for the
cptui_post_typesandcptui_taxonomiesoptions. As confirmed in user threads, these are safe to delete once you have exported your settings to code or no longer need the plugin. Important: Only do this if you have already uninstalled CPTUI or are certain you will not need these settings again.
Step 5: Check for Third-Party Plugin References
As one user discovered, their deleted post types were still appearing in the admin menu because they were still listed in Advanced Custom Fields (ACF). Check any plugins that integrated with your custom post type (e.g., ACF, Admin Menu Editor, TaxoPress) and remove any references to the deleted CPT or taxonomy from within their settings.
Frequently Asked Questions
Q: I accidentally deleted a post type! Can I get my posts back?
A>Yes. If you recreate the custom post type in CPTUI using the exact same slug as before, all of your existing posts will reappear and be accessible again. Your content is safe in the database.
Q: Do I need to keep CPT UI installed for my post types to work?
A>Yes, unless you take an extra step. CPTUI actively registers your post types. If you deactivate or uninstall it, your post types will cease to be registered and their content will become inaccessible. To remove the plugin, you must first use the "Get Code" feature in the CPTUI Tools menu to export your post type configuration as PHP code. You can then add this code to your theme's functions.php file or a custom functionality plugin.
Q: A user role can't delete posts from my custom post type. Is this CPTUI's fault?
A>According to support threads, CPTUI does not implement custom restrictions on user capabilities. This issue is likely related to your role management plugin or how user capabilities are configured elsewhere. The "Capability type" field in CPTUI should generally be left as "post" to inherit standard WordPress permissions.
By following this guide, you can confidently manage your custom post types and taxonomies, ensuring a clean database even after removing them from your site.
Related Support Threads Support
-
Deleting CPTs – How to “clean” everything (rewrite rules included)https://wordpress.org/support/topic/deleting-cpts-how-to-clean-everything-rewrite-rules-included/
-
delete user does not delete associated CPThttps://wordpress.org/support/topic/delete-user-does-not-delete-associated-cpt/
-
deleted cpts still appearing in backend menuhttps://wordpress.org/support/topic/deleted-cpts-still-appearing-in-backend-menu/
-
Recovering CPThttps://wordpress.org/support/topic/recovering-cpt/
-
Content in Fields Delete on Publish (REST API ISSUE)https://wordpress.org/support/topic/content-in-fields-delete-on-publish-rest-api-issue/
-
Do I need to keep CPT UI installed after creating custom post types?https://wordpress.org/support/topic/do-i-need-to-keep-cpt-ui-installed-after-creating-custom-post-types/
-
Where is the content when delete custom post type?https://wordpress.org/support/topic/where-is-the-content-when-delete-custom-post-type/
-
CPT Content in phpMyAdmin?https://wordpress.org/support/topic/cpt-content-in-phpmyadmin/
-
User role can’t delete posthttps://wordpress.org/support/topic/user-role-cant-delete-post/
-
wp_options tablehttps://wordpress.org/support/topic/wp_options-table-2/
-
How to completely delete a CPT?https://wordpress.org/support/topic/how-to-completely-delete-a-cpt/
-
Taxonomy Created by CPT-UI – Delete Issuehttps://wordpress.org/support/topic/taxonomy-created-by-cpt-ui-delete-issue/