是否可以为多个自定义帖子类型添加相同的类别?
例如,
优惠券发布类型-交易发布类型-两者都应共享常见类别,例如健康,旅行等。
但是,当我们创建新的帖子类型时,看起来,我们还需要提供自定义类别。
您有什么线索如何创建没有自定义类别的自定义帖子类型?
是的,自定义帖子类型可以具有多个分类法(类别,标签,自定义)
是的,您可以使用没有分类的自定义帖子类型。
可以将类别添加到自定义帖子类型中,如下所示:
'taxonomies' => array('category'), // <--- add this (or use 'post_tag' to add tags to the CPT)
'public' => true,
'show_ui' => true,
'exclude_from_search' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'query_var' => true
如果要向多个帖子类型添加自定义分类法,则可以执行以下操作:
function people_init() {
// create a new taxonomy
register_taxonomy(
'people',
array('post','page','custom_post_type'), // <-- 'people' taxo added to posts, pages, & custom_post_type
array(
'label' => __( 'People' ),
'rewrite' => array( 'slug' => 'person' ),
'capabilities' => array(
'assign_terms' => 'edit_guides',
'edit_terms' => 'publish_guides'
)
)
);}add_action( 'init', 'people_init' );
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句