简体   繁体   中英

Remove default “category” taxonomy from custom post type

I've created a custom post type called Resources . I want this post type to support the following custom taxonomies:

  • Subject
  • Type
  • Sector

And I have registered the post type accordingly:

register_post_type(
    'resources',
    tp_build_post_args(
        'resources', 'Resource', 'Resources',
        array(
            'menu_icon'     => 'dashicons-welcome-write-blog',
            'menu_position' => 20,
            'has_archive'   => true,
            'public'      => true,
            'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
            'taxonomies' => array('sector', 'subject', 'type')
            //'rewrite' => array ( 'slug' => 'resources', 'with_front' => false )
        )
    )
);

And have defined the resources taxonomy like so:

register_taxonomy(  
    'resource', 
    'resources', 
    // 'labels'   => array(
    //     'name'          => 'Resource Categories',
    //     'singular_name' => 'Resource Category',
    // ),
    array(  
        'hierarchical' => true,  
        'query_var' => true,
    )  
);  

And this outputs the following in WordPress backend:

在此处输入图片说明

I do not want the categories option, is there a way to remove this? I know if no label is defined for when running register_taxonomy , then "categories" is the default output. But I do not want a label to replace it, I don't want it (just want to see subject, type and sector).

How can I go about this?

Well, removing the default taxonomy from custom post type in wordpress is not too hard.

Just change your code with this:

register_taxonomy(  
    'resource', 
    'resources', 
    array(  
        'hierarchical' => true,  
        'query_var' => true,
        'show_ui'                    => true,
        'show_in_quick_edit'         => false,
        'meta_box_cb'                => false,
    )  
);  

show_ui = false, removes the metabox from admin menu, quick edit screen and edit screen. You can hide meta box and ui in quick edit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM