How to Find the Names of the Custom Post Types Used in Your WordPress Site

By Andrew Gehman Custom Post Types

I recently ran into a situation while working on a WordPress site where I needed to query for custom post types that were created by a plugin I was using, but I didn’t know the name of the specific post type. I consulted the plugin developer’s documentation, and did a bit of ‘Googling,’ but came up empty.

Before getting too far into my search, I decided to go about it a different way. Rather than looking for a specific post type without knowing what that post type is called, I looked for a way to output all available post types in WordPress.

Update: We made a plugin called Find My Custom Post Types that does this for you! If you’d like to know how to do this yourself with code, keep reading. If you’d like to use the plugin, follow the link above or scroll down to the bottom of the post.

As luck would have it, WordPress has a get_post_types() function that returns the names of all standard post types and custom post types.  So, to find out all the post types available to us, we’ll use the get_post_types() function along with the print_r() function in PHP to return and display a result. You can drop this code into any page or template file and view the result. I’ve added <pre></pre> tags to give us a cleaner, more readable output.

<?php $show_post_types = get_post_types(); ?> 

<pre>

  <?php print_r($show_post_types); ?> 

</pre>

You should see results returned that include all the built in WordPress Post Types, along with any other available post types that may have been added by any plugins or your theme.  In this example, we have several WordPress plugins installed, including bbpress, Advanced Custom Fields, and The Events Calendar that have created their own post types.

Array
(
    [post] => post
    [page] => page
    [attachment] => attachment
    [revision] => revision
    [nav_menu_item] => nav_menu_item
    [forum] => forum
    [topic] => topic
    [reply] => reply
    [acf-field-group] => acf-field-group
    [acf-field] => acf-field
    [tribe_venue] => tribe_venue
    [tribe_organizer] => tribe_organizer
    [tribe_events] => tribe_events
)

Since we aren’t concerned with the built WordPress post types, we can tweak our code a bit so that we don’t return those post types. The code below adds arguments to our initial query so that we are only returning public post types (visible to authors and readers and are ‘queryable’) and not returning the built in post types like posts and pages.

<?php $args = array(
     'public'   => true,
     '_builtin' => false
);?>

<?php $show_post_types = get_post_types( $args ); ?> 

<pre>
  <?php print_r($show_post_types); ?> 
</pre>

Now we should be looking at only public post types that aren’t built in to WordPress.

Array
(
    [forum] => forum
    [topic] => topic
    [reply] => reply
    [tribe_events] => tribe_events
)

This ‘should’ make it easy to determine just what the name of the post type is that we want to use in our query.  Since I was looking for an events plugin post type, it’s a pretty safe bet that tribe_events is the post type I am looking for. (and it was!)

Find My Custom Post Type Plugin

As mentioned earlier in the post, we created a plugin that does this for you called Find My Custom Post Types. After installing and activating the plugin, you call find the list of registered custom post types in the WordPress admin menu under Tools > Find My CPTs. Enjoy!

View Comments

6 responses to “How to Find the Names of the Custom Post Types Used in Your WordPress Site”

    • You’d paste it into template file where the custom post type is being used. For example, if you are trying to find the name of a custom post type that displays events on every WordPress page, you’d paste it in page.php.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Are You Ready To Do More with Mind?

Click the link below to get started!

Work With Mind