WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 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
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'); 
share|improve this answer
thank you very much ! – Quang Trung Nguyen Nov 12 '13 at 8:41

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.