get_post_type_object

Retrieves a post type object by name.

Description

(WP_Post_Type|null) get_post_type_object( (string) $post_type ); 

Returns (WP_Post_Type|null)

WP_Post_Type object if it exists, null otherwise.

Parameters (1)

0. $post_type (string)
The name of a registered post type.

Usage

  1. if ( !function_exists( 'get_post_type_object' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The name of a registered post type. 
  5. $post_type = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_post_type_object($post_type); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function get_post_type_object( $post_type ) { 
  2. global $wp_post_types; 
  3.  
  4. if ( ! is_scalar( $post_type ) || empty( $wp_post_types[ $post_type ] ) ) { 
  5. return null; 
  6.  
  7. return $wp_post_types[ $post_type ];