post_type_exists()WP 3.0.0

Determines whether the specified post type is registered.

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

0

#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() code WP 6.4.3

function post_type_exists( $post_type ) {
	return (bool) get_post_type_object( $post_type );
}