get_post_type_object( string $post_type )

Retrieves a post type object by name.


Description

See also


Parameters

$post_type

(Required) The name of a registered post type.


Return

(WP_Post_Type|null) WP_Post_Type object if it exists, null otherwise.


Source

File: wp-includes/post.php

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 ];
}


Changelog

Changelog
Version Description
WP-4.6.0 Object returned is now an instance of WP_Post_Type.
WP-3.0.0 Introduced.