1

I'm writing a small plugin for Visual Composer. I need to list all custom post types but I don't know when to call the query to fetch all post types. My plugin gets initialized by after_setup_theme, but the function which queries the custom post types don't list custom post types, because its executed too early.

The problem: custom post types can be created within theme files (e.g. function.php) or plugins (like Custom Post Type UI).

Which action should I use to get all custom post types? I know that Advanced Custom Fields does the same (you can create custom fields for every (custom) post type), but I can't find the piece of code that does the trick.

3
  • Do you mean an action that fires after a post type is registered? That's registered_post_type – henrywright Nov 7 '14 at 11:00
  • Hmmm and what happens if a theme and a plugin registers a custom post type? The action will be fired multiple times, right? I think I need an action or a routine that let me execute my code after all post types are registered. – Slevin Nov 7 '14 at 11:10
  • Ah OK, I think I misunderstood your question :) – henrywright Nov 7 '14 at 11:37
2

Just as @PieterGoosen mentioned, in a deleted comment, the post types should be registered within a init hook callback.

The after_setup_theme action is fired before init, so that hook will not help you.

Try for example hooks fired after init, like wp_loaded.

Here's for example a list of the actions order from my vanilla install.

2
  • When I saw your first answer and the comments after mine, I thought, damn, did I misread something? Hahahha, had me second guesing there. +1 – Pieter Goosen Nov 7 '14 at 11:26
  • hehe it looks like I misunderstood the question at first read, but you were on the right track ;-) – birgire Nov 7 '14 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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