[英]Remove default “category” taxonomy from custom post type
I've created a custom post type called Resources
. 我创建了一个名为
Resources
的自定义帖子类型。 I want this post type to support the following custom taxonomies: 我希望该帖子类型支持以下自定义分类法:
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: 并在WordPress后端中输出以下内容:
I do not want the categories
option, is there a way to remove this? 我不希望使用
categories
选项,是否可以删除此选项? I know if no label is defined for when running register_taxonomy
, then "categories" is the default output. 我知道如果在运行
register_taxonomy
时未定义任何标签,则“类别”是默认输出。 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. 好吧,从wordpress中的自定义帖子类型中删除默认分类法并不是一件难事。
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. show_ui = false,从管理菜单,快速编辑屏幕和编辑屏幕中删除元框。 You can hide meta box and ui in quick edit.
您可以在快速编辑中隐藏meta box和ui。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.