0

The dilemma is that get_post_types() inside the plugin I am creating. And from researching now all post types are not registered until "wp_loaded". However, "wp_loaded" is executed when all plugins are loaded.

All post types have yet to be registered, but I need them in my plugin. Is there a way to solve this problem? My custom post types are attached to init.

    class MyPlugin
    {

        public static function init() {
        self::load_plugin_textdomain();
        self::register_post_status();
        $pt = MyPlugin::get_post_types();
        //add a column for each post type here
        //add_action and add_filter
        }

        private static function get_post_types() 
        {
                return get_post_types( array( 'public' => true ), 'objects' );
        }

    }

add_action( 'init', create_function( '', 'return MyPlugin::init();' ) );
  • it's not clear what the problem is. your get_post_types code should be hooked to run after post types are created. add the code you have tried to your question. – Milo Oct 2 '15 at 14:38
  • I've added some code that gives the general approach of my plugin – Satbir Kira Oct 2 '15 at 14:52
  • you don't specify a priority on your action, so it will run in whatever position it gets placed in the queue, which may be before something else adds its init actions. if your goal is to ultimately modify the registered post types, theres already an action for that: registered_post_type. – Milo Oct 2 '15 at 16:48
  • @Milo registered_post_type does not include custom post types – Satbir Kira Oct 5 '15 at 7:18
  • registered_post_type action is triggered for all post types including custom types. – Milo Oct 5 '15 at 14:42
0

I don't think you’ll be able to get all the post types that are registered on init. (other plugins may register extra post types)

Can't you hook into wp_loaded?

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.