unregister_post_type

Unregisters a post type.

Description

(bool|WP_Error) unregister_post_type( (string) $post_type ); 

Can not be used to unregister built-in post types.

Returns (bool|WP_Error)

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

Parameters (1)

0. $post_type (string)
Post type to unregister.

Usage

  1. if ( !function_exists( 'unregister_post_type' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Post type to unregister. 
  5. $post_type = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = unregister_post_type($post_type); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function unregister_post_type( $post_type ) { 
  2. global $wp_post_types; 
  3.  
  4. if ( ! post_type_exists( $post_type ) ) { 
  5. return new WP_Error( 'invalid_post_type', __( 'Invalid post type.' ) ); 
  6.  
  7. $post_type_object = get_post_type_object( $post_type ); 
  8.  
  9. // Do not allow unregistering internal post types. 
  10. if ( $post_type_object->_builtin ) { 
  11. return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); 
  12.  
  13. $post_type_object->remove_supports(); 
  14. $post_type_object->remove_rewrite_rules(); 
  15. $post_type_object->unregister_meta_boxes(); 
  16. $post_type_object->remove_hooks(); 
  17. $post_type_object->unregister_taxonomies(); 
  18.  
  19. unset( $wp_post_types[ $post_type ] ); 
  20.  
  21. /** 
  22. * Fires after a post type was unregistered. 
  23. * @since 4.5.0 
  24. * @param string $post_type Post type key. 
  25. */ 
  26.  
  27. return true;