最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

metabox - Custom taxonomy hide meta box but show in menu

programmeradmin1浏览0评论

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 );
发布评论

评论列表(0)

  1. 暂无评论