How to get the args of my custom post types

Support MB Custom Post Type How to get the args of my custom post typesResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #35982
    Alaan TVAlaan TV
    Participant

    How can I get the $args of a custom post type?

    I have 4 custom post types and I want to get the post types that have `'show_in_menu' => 'edit.php'.

    I'm planning to create a function that controls the menu item position of these custom post types in the Posts menu.

    I tried to run the function get_post_types(); and didn't get my custom post types listed.

    Any advice, please?

    #35986
    Alaan TVAlaan TV
    Participant

    I just need a way to get the $args of my custom post types. Please help!

    #35990
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can get the PHP code and then put it to the file functions.php in the theme/child theme folder to control the $args manually. Refer to this documentation https://docs.metabox.io/extensions/mb-custom-post-type/#getting-php-code

    #35991
    Alaan TVAlaan TV
    Participant

    What I meant was to get the $args after registering the custom post type.

    Is there any WordPress or MetaBox function that returns the $args of a certain registered custom post type?

    In my example, I need to get the 'show_in_menu' value.

    #35994
    Alaan TVAlaan TV
    Participant

    I find a way to get the $args of an existing custom post type.

    I tried first to use the get_post_types() function, but it was always listing the built-in post types even when I pass the '_builtin' => false in the function args like this:

    $args = array(
       '_builtin' => false
    );
    $post_types = get_post_types( $args );
    

    I found that we can use global $wp_post_types like this:
    $wp_post_types['custom_post_type_slug']->arg_slug;.

    For example:

    $wp_post_types['custom_post_type_slug']->labels;
    $wp_post_types['custom_post_type_slug']->menu_icon;
    $wp_post_types['custom_post_type_slug']->show_in_menu;
    ...
    
    #36006
    Long NguyenLong Nguyen
    Moderator

    Thanks for sharing your solution.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.