get_post_type_object

The timeline below displays how wordpress function get_post_type_object has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.1

/**
 * Retrieves a post type object by name.
 *
 * @since 3.0.0
 * @since 4.6.0 Object returned is now an instance of `WP_Post_Type`.
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type()
 *
 * @param string $post_type The name of a registered post type.
 * @return WP_Post_Type|null WP_Post_Type object if it exists, null otherwise.
 */
function get_post_type_object($post_type)
{
    global $wp_post_types;
    if (!is_scalar($post_type) || empty($wp_post_types[$post_type])) {
        return null;
    }
    return $wp_post_types[$post_type];
}

WordPress Version: 4.6

/**
 * Retrieves a post type object by name.
 *
 * @since 3.0.0
 * @since 4.6.0 Object returned is now an instance of WP_Post_Type.
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type()
 *
 * @param string $post_type The name of a registered post type.
 * @return WP_Post_Type|null WP_Post_Type object if it exists, null otherwise.
 */
function get_post_type_object($post_type)
{
    global $wp_post_types;
    if (!is_scalar($post_type) || empty($wp_post_types[$post_type])) {
        return null;
    }
    return $wp_post_types[$post_type];
}

WordPress Version: 4.4

/**
 * Retrieve a post type object by name.
 *
 * @since 3.0.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type()
 *
 * @param string $post_type The name of a registered post type.
 * @return object|null A post type object.
 */
function get_post_type_object($post_type)
{
    global $wp_post_types;
    if (!is_scalar($post_type) || empty($wp_post_types[$post_type])) {
        return null;
    }
    return $wp_post_types[$post_type];
}

WordPress Version: 4.3

/**
 * Retrieve a post type object by name.
 *
 * @since 3.0.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type()
 *
 * @param string $post_type The name of a registered post type.
 * @return object|null A post type object.
 */
function get_post_type_object($post_type)
{
    global $wp_post_types;
    if (empty($wp_post_types[$post_type])) {
        return null;
    }
    return $wp_post_types[$post_type];
}

WordPress Version: 4.0

/**
 * Retrieve a post type object by name.
 *
 * @since 3.0.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type()
 *
 * @param string $post_type The name of a registered post type.
 * @return object A post type object.
 */
function get_post_type_object($post_type)
{
    global $wp_post_types;
    if (empty($wp_post_types[$post_type])) {
        return null;
    }
    return $wp_post_types[$post_type];
}

WordPress Version: 3.9

/**
 * Retrieve a post type object by name
 *
 * @since 3.0.0
 * @uses $wp_post_types
 * @see register_post_type
 * @see get_post_types
 *
 * @param string $post_type The name of a registered post type
 * @return object A post type object
 */
function get_post_type_object($post_type)
{
    global $wp_post_types;
    if (empty($wp_post_types[$post_type])) {
        return null;
    }
    return $wp_post_types[$post_type];
}

WordPress Version: 3.7

/**
 * Retrieve a post type object by name
 *
 * @package WordPress
 * @subpackage Post
 * @since 3.0.0
 * @uses $wp_post_types
 * @see register_post_type
 * @see get_post_types
 *
 * @param string $post_type The name of a registered post type
 * @return object A post type object
 */
function get_post_type_object($post_type)
{
    global $wp_post_types;
    if (empty($wp_post_types[$post_type])) {
        return null;
    }
    return $wp_post_types[$post_type];
}