WordPress at Your Fingertips

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

#1 Check whether the post type is registered

if( post_type_exists( 'post' ) ){
	echo 'Post type "post" exists!';
}

Notes

Changelog

Since 3.0.0 Introduced.

Code of post_type_exists() WP 5.8

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

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Log In