• Resolved andreawp101

    (@andreawp101)


    Hi,

    This is related to the hook shared in this topic: https://www.ads-software.com/support/topic/action-hook-for-post-type-creation/

    When i call get_post_type_object() or get_post_types() inside this hook, it is always returning NULL even post types are available. Is there any workaround for this.

    Note: When I call it inside a different hook, it can get post types/post type objects properly.

    function do_some_actions($data) {
        // I need to call get_post_type_object but this is always returning NULL
        $parent_post_type_object = get_post_type_object($parent_post_type);
        
        // Also when getting all post types, this is also returning NULL
        $custom_post_types = get_post_types(array('public' => true, '_builtin' => false), 'objects');
    }
    add_action( 'cptui_after_update_post_type', 'do_some_actions' );
Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    That hook is running on init but also on priority 8 so it’s very likely running before most post types have been registered for that request.

    If you’re looking to do something with the post type that was just saved, you’ll want to get that from this: $data['cpt_custom_post_type']['name'] and the $data object that gets passed in that has all of the information that was just saved for that post type.

    Beyond that, I’d need to know more details about what you’re trying to achieve after saving of post type settings to know what to potentially suggest.

Viewing 1 replies (of 1 total)
  • The topic ‘Get post types inside the post type creation action hook’ is closed to new replies.