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.

I write a simple plugin to get all post types by using get_post_types. But it does not work.

$customPost = get_post_types(array(), 'object');

it returns default post types of wordpress.

When i install Woocommerce plugin, it does not show the custom post types of woocommerce ?

Does it relate to plugin order ?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Post types in WordPress are not saved some where, they are registered everytime you request a page.

So to get all post types, you have to wait untill all post types are registered.

Normally, all post types are registered before the hook wp_loaded is fired.

So change your code in something like this:

add_action( 'wp_loaded', 'my_get_all_types' );

function my_get_all_types() {
  // if you want only custom post types use '_builtin'=> false in the arguments array
  // 2nd argument should be 'objects' not 'object'
  $cpts = get_post_types( array( '_builtin'=> false ), 'objects'); 
  var_dump($cpts);
}
share|improve this answer
    
thank you very much ! –  Quang Trung Nguyen Nov 12 '13 at 8:41
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.