post_type_exists()
Determines whether the specified post type is registered.
Uses: get_post_type_object()
1 time — 0.000018 sec (very fast) | 50000 times — 0.03 sec (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 'The post type exists!'; }
Notes
Changelog
Since 3.0.0 | Introduced. |
post_type_exists() post type exists code WP 6.4.3
function post_type_exists( $post_type ) { return (bool) get_post_type_object( $post_type ); }