Tutorial

How to Check if a Post Type Exists in WordPress

The function post_type_exists checks if a post type is registered in WordPress.

Syntax

post_type_exists($post_type) returns TRUE if $post_type is the identifier of a registered post type, otherwise returns FALSE.

Learn here how to register a post type in WordPress.

// Is 'post' a registered post type?
$post_type_exists_post = post_type_exists('post');

// Is 'page' a registered post type?
$post_type_exists_page = post_type_exists('page');

// Is 'ns_book_cpt' a registered post type?
$post_type_exists_book = post_type_exists('ns_book_cpt');

Further reading

I recommend the other tutorials in this series to learn more about post types in WordPress.

Source code

The source code developed in this tutorial is available here.

WordPress

Related Tutorials

Open chat
Need help?
Hi! 🤝 Open the chat if you have any question, feedback, or business proposal. I would love to hear from you.