unregister_post_type()
Unregisters (deletes) a post type.
Can not be used to unregister built-in post types: posts, pages, attachments etc — all those who have _builtin
parameter when was registered with register_post_type.
When unregistering a post type, everything associated with it is also removed: rewrite rules, meta boxes, hooks, taxonomies, etc.
To unregister a taxonomy, use unregister_taxonomy().
Hooks from the function
Return
true|WP_Error
. True on success, WP_Error on failure or if the post type doesn't exist.
Usage
unregister_post_type( $post_type );
- $post_type(string) (required)
- 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. |