最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

metabox - Custom taxonomy hide meta box but show in menu

matteradmin6PV0评论

If set show_ui false, this hide the taxonomy meta box and admin menu link both, how to hide only meta box?

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => false,
    'show_admin_column' => false,
    'show_in_menu'      => true,
    'show_in_nav_menus' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'wheel' ),
);

register_taxonomy( 'wheel', array( 'product' ), $args );

If set show_ui false, this hide the taxonomy meta box and admin menu link both, how to hide only meta box?

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => false,
    'show_admin_column' => false,
    'show_in_menu'      => true,
    'show_in_nav_menus' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'wheel' ),
);

register_taxonomy( 'wheel', array( 'product' ), $args );
Share Improve this question asked Jun 30, 2016 at 19:09 SeviSevi 3152 gold badges4 silver badges8 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 7

You're looking for the meta_box_cb argument.

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => false,
    'show_admin_column' => false,
    'show_in_menu'      => true,
    'show_in_nav_menus' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'wheel' ),

    'meta_box_cb'       => false,
);

register_taxonomy( 'wheel', array( 'product' ), $args );

You can also define a custom callback function for displaying your own metabox if you'd like. Refer to the documentation for register_taxonomy().

i registered the taxonomy without showing any of the UI element

add_action( 'init', 'kia_register_featured_tax', 0 );

function kia_register_featured_tax(){
    if(!taxonomy_exists('portfolio_featured')){
        $labels = array(
            'name' => _x( 'Featured', $this->plugin_domain ),
            'singular_name' => _x( 'Featured', $this->plugin_domain )           
        );

        $args = array(
            'labels' => $labels,
            'rewrite' => array( 'slug' => 'portfolio-featured' ),
            'query_var' => true,
            'public' => true,
            'show_ui' => false,
            'show_tagcloud' => false,
            'show_in_nav_menus' => false,
        );
        register_taxonomy( 'portfolio_featured', array( 'portfolio' ), $args );
    }
}

To clarify the answer from @NateWr, you need to set show_ui to true, set show_in_menu to true and set meta_box_cb to false:

$args = array(
    'show_ui'           => true,
    'show_in_menu'      => true,
    'meta_box_cb'       => false,
    //Plus anything else you need...
);

register_taxonomy( 'wheel', array( 'product' ), $args );
Post a comment

comment list (0)

  1. No comments so far