WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to get a list (array) of all the post types I registered.

Precisely I would like to retrieve their slugs.

Could someone help me? thanks!

share|improve this question
up vote 4 down vote accepted

@EAMann's answer is correct, but there's already a build in WordPress function for fetching all registered post types: get_post_types

// hook into init late, so everything is registered
// you can also use get_post_types where ever.  Any time after init is usually fine.
add_action( 'init', 'wpse34410_init', 0, 99 );
function wpse34410_init() 
    // types will be a list of the post type names
    $types = get_post_types();

    // get the registered data about each post type with get_post_type_object
    foreach( $types as $type )
        $typeobj = get_post_type_object( $type );

        // need the actual slug?  this will do it...
        if( isset( $typeobj->rewrite->slug ) )
            // you'll probably want to do something else.
            echo $typeobj->rewrite->slug;
share|improve this answer
thank you both guys – unfulvio Nov 22 '11 at 0:43
TIP: You don't need to call get_post_type_object if you set the get_post_types call to return objects to you, eg. $types = get_post_types( '', 'objects' ); – t31os Nov 23 '11 at 9:53
Good call, thanks! – chrisguitarguy Nov 23 '11 at 14:41

When you call register_post_type(), it adds your new post type to a global variable called $wp_post_types. So you can get a list of all of your post types from that:

function get_registered_post_types() {
    global $wp_post_types;

    return array_keys( $wp_post_types );

The $wp_post_types variable is an array that contains your CPT definitions, with each set of CPT arguments (labels, capabilities, etc) mapped to the slug of the CPT. Calling array_keys() will give you an array of the slugs of your CPTs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.