WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/post type exists

Description

This Conditional Tag checks if a post type exists by passing a post type name an argument. This is a boolean function and uses a global $wp_post_types variable for checking the post type existence, meaning it returns either TRUE if the post type exists or FALSE if it doesn't exist. The post type must be a registered post type.

Usage

<?php post_type_exists$post_type ); ?>

Parameters

$post_type
(string) (required) Post type.
Default: None

Return Value

(boolean) 
True on success, false on failure.

Examples

if ( post_type_exists( 'book' ) ) {
   echo 'the Book post type exists';
}
$exists = post_type_exists( 'post' );
// returns true
 
$exists = post_type_exists( 'page' );
// returns true
 
$exists = post_type_exists( 'book' );
// returns true if book is a registered post type
 
$exists = post_type_exists( 'xyz' );
// returns false if xyz is not a registered post type

Change Log

Source File

post_type_exists() is located in wp-includes/post.php.

Related

taxonomy_exists()

Post Types: register_post_type(), add_post_type_support(), remove_post_type_support(), post_type_supports(), post_type_exists(), set_post_type(), get_post_type(), get_post_types(), get_post_type_object(), get_post_type_capabilities(), get_post_type_labels(), is_post_type_hierarchical(), is_post_type_archive(), post_type_archive_title()

See also index of Function Reference and index of Template Tags.