unregister_post_type()
Cancels the registration of the specified post type. Deletes the post type.
Does not work with built-in post types: posts, pages, attachments, etc., i.e., those that have the _builtin parameter specified during registration using register_post_type.
When deleting a post type, everything associated with it is removed: query parameters, permalink rules, etc.
To unregister a taxonomy, use unregister_taxonomy().
Hooks from the function
Returns
true|WP_Error.
True, on successful cancellation.- WP_Error, on unsuccessful cancellation or when the specified post type does not exist.
Usage
unregister_post_type( $post_type );
- $post_type(string) (required)
- The name of the post type to unregister.
Examples
#1 Unregister a post type
Suppose that some plugin or theme registers post type product, and we don't need it:
// All post types are registered during ``init`` action,
// so you should unregister them after it.
// Use for that ``wp_loaded`` action or ``init`` but with lower priority.
add_action('init', 'my_unregister_post_type', 999);
function my_unregister_post_type(){
unregister_post_type('product');
}
Notes
- Global. Array. $wp_post_types List of post types.
Changelog
| Since 4.5.0 | Introduced. |