post_type_exists( string $post_type ): bool

Determines whether a post type is registered.


Description

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

Top ↑

See also


Top ↑

Parameters

$post_type string Required
Post type name.

Top ↑

Return

bool Whether post type is registered.


Top ↑

Source

File: wp-includes/post.php. View all references

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


Top ↑

Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Basic Examples

    $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

You must log in before being able to contribute a note or feedback.