Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I call get_post_types() in a plugin the output is registering only the basic set of post types. Here is the output:

array(5) { ["post"]=> string(4) "post" ["page"]=> string(4) "page" ["attachment"]=> string(10) "attachment" ["revision"]=> string(8) "revision" ["nav_menu_item"]=> string(13) "nav_menu_item" }

In this wordpress theme, however, I have registered a custom post type called 'artist', but it is not showing up. If, however, I call get_post_types() in the index.php file it does how the registered posts:

array(8) { ["post"]=> string(4) "post" ["page"]=> string(4) "page" ["attachment"]=> string(10) "attachment" ["revision"]=> string(8) "revision" ["nav_menu_item"]=> string(13) "nav_menu_item" ["acf"]=> string(3) "acf" ["artist"]=> string(6) "artist" ["release"]=> string(7) "release" }

Does anyone know why this is happening and how to get around the problem?

share|improve this question
    
Where and when do you call get_post_types()? –  kaiser May 22 '13 at 23:40
add comment

1 Answer

up vote 1 down vote accepted

You have to wait with your call until the theme has registered its post type (it really should not do that anyway):

add_action( 'after_setup_theme', 'list_post_types', 20 );

function list_post_types()
{
    var_export( get_post_types() );
}
share|improve this answer
add comment

Your Answer

 
discard

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.