unregister_post_type()WP 4.5.0

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


true|WP_Error. True on success, WP_Error on failure or if the post type doesn't exist.


unregister_post_type( $post_type );
$post_type(string) (required)
Post type to unregister.



#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(){


  • Global. Array. $wp_post_types List of post types.


Since 4.5.0 Introduced.

unregister_post_type() code WP 6.5.3

function unregister_post_type( $post_type ) {
	global $wp_post_types;

	if ( ! post_type_exists( $post_type ) ) {
		return new WP_Error( 'invalid_post_type', __( 'Invalid post type.' ) );

	$post_type_object = get_post_type_object( $post_type );

	// Do not allow unregistering internal post types.
	if ( $post_type_object->_builtin ) {
		return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) );


	unset( $wp_post_types[ $post_type ] );

	 * Fires after a post type was unregistered.
	 * @since 4.5.0
	 * @param string $post_type Post type key.
	do_action( 'unregistered_post_type', $post_type );

	return true;