get_post_type_object() WP 1.0
Retrieves a post type object by name.
1 time = 0.000068s = very fast | 50000 times = 2.36s = fast | PHP 7.0.5, WP 4.5.2
No Hooks.
Return
WP_Post_Type/null. WP_Post_Type object if it exists, null otherwise.
Usage
get_post_type_object( $post_type );
- $post_type(string) (required)
- The name of a registered post type.
Notes
- Global. Array. $wp_post_types List of post types.
- See: register_post_type()
Changelog
Since 3.0.0 | Introduced. |
Since 4.6.0 | Object returned is now an instance of WP_Post_Type. |
Code of get_post_type_object() get post type object WP 5.6
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 ];
}