On this page
unregister_post_type( string $post_type ): true|WP_Error
Unregisters a post type.
Description
Cannot be used to unregister built-in post types.
Parameters
$post_typestring Required-
Post type to unregister.
Return
true|WP_Error True on success, WP_Error on failure or if the post type doesn't exist.
Source
File: wp-includes/post.php. View all references
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' ) );
}
$post_type_object->remove_supports();
$post_type_object->remove_rewrite_rules();
$post_type_object->unregister_meta_boxes();
$post_type_object->remove_hooks();
$post_type_object->unregister_taxonomies();
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;
}
Hooks
- do_action( 'unregistered_post_type',
string $post_type ) -
Fires after a post type was unregistered.
Related
Uses
| Uses | Description |
|---|---|
| post_type_exists() wp-includes/post.php | Determines whether a post type is registered. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
| get_post_type_object() wp-includes/post.php | Retrieves a post type object by name. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Changelog
| Version | Description |
|---|---|
| 4.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/unregister_post_type