我有一个名为“资源”的自定义帖子类型。
How I\'ve defined the taxonomy:
register_taxonomy(
\'resource\', // the name of the taxonomy
\'resources\', // post type name
array(
\'hierarchical\' => true,
//\'label\' => \'Resources\', // display name
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'resources\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before
)
)
);
How I\'ve registered the post type:
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(\'post_tag\', \'type\', \'sector\')
)
)
);
正如你所看到的,我没有
category
在中选择的选项
\'taxonomies\' => array(\'post_tag\', \'type\', \'sector\')
, 但它在管理中显示为一个选项:
为什么会这样?
最合适的回答,由SO网友:Sally CJ 整理而成
首先,我认为“类别”实际上是用于自定义分类法resource
而不是标准category
分类学但在菜单中,它被标记为Categories
因为您没有为resource
分类法(因为label
已注释掉,默认为Categories
):
register_taxonomy(
\'resource\', // the name of the taxonomy
\'resources\', // post type name
array(
\'hierarchical\' => true,
//\'label\' => \'Resources\', // display name <- this
...
)
);
其次
resource
分类法实际上分配给
resources
帖子类型,尽管分类法不在帖子类型的列表中
taxonomies
属性:
register_taxonomy(
\'resource\', // the name of the taxonomy
\'resources\', // post type name <- here, the taxonomy will be assigned to this post type
array( ... )
);
如果你真的不想
resource
要分配给
resources
post type,然后将post type设置为
null
或者不管合适的职位类型是什么:
register_taxonomy(
\'resource\', // the name of the taxonomy
null, // set to null, which means don\'t assign to `resources` or any post types..
array( ... )
);
或者,您可以使用
unregister_taxonomy_for_object_type()
要从帖子类型取消分配分类,请执行以下操作:
// Call after the post type and taxonomy are both registered.
unregister_taxonomy_for_object_type( \'resource\', \'resources\' );