WordPress at a glance

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: wp-includes/post.php WP 5.2.2

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

Related Functions

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Hello, !     Log In . Register