post_type_exists() WP 3.0.0
Determines whether the specified post type is registered.
Works based on: get_post_type_object()
1 time = 0.000018s = very fast | 50000 times = 0.03s = speed of light
No Hooks.
Return
true/false. Whether post type is registered.
Usage
post_type_exists( $post_type );
- $post_type(string) (required)
- Post type name.
Examples
#1 Check whether the post type is registered
if( post_type_exists( 'post' ) ){ echo 'Post type "post" exists!'; }
Notes
- See: get_post_type_object()
Changelog
Since 3.0.0 | Introduced. |
Code of post_type_exists() post type exists WP 5.6
function post_type_exists( $post_type ) {
return (bool) get_post_type_object( $post_type );
}