admin管理员组文章数量:1431420
All, I'm creating my own post type using the following code:
add_action( 'init', 'create_team_post_type' );
function create_team_post_type() {
register_post_type( 'team',
array(
'labels' => array(
'name' => __( 'Teams' ),
'singular_name' => __( 'Team' )
),
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('category'),
'supports' => array('title','editor','thumbnail')
)
);
}
In this I'm allowing a category. When I click on the category for this I see the categories already listed from my post categories. I'd like to only show the categories for this custom post type. In addition when I add a new category to the custom post type I only want it to apply to this custom post type. How do I go about doing this?
All, I'm creating my own post type using the following code:
add_action( 'init', 'create_team_post_type' );
function create_team_post_type() {
register_post_type( 'team',
array(
'labels' => array(
'name' => __( 'Teams' ),
'singular_name' => __( 'Team' )
),
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('category'),
'supports' => array('title','editor','thumbnail')
)
);
}
In this I'm allowing a category. When I click on the category for this I see the categories already listed from my post categories. I'd like to only show the categories for this custom post type. In addition when I add a new category to the custom post type I only want it to apply to this custom post type. How do I go about doing this?
Share Improve this question asked Nov 16, 2014 at 19:51 user1048676user1048676 4373 gold badges9 silver badges25 bronze badges1 Answer
Reset to default 22I would say that you need to also create a custom taxonomy if you want it to be limited to the one post type. "Categories" is already connected to posts by default.
From the WordPress Codex
function people_init() {
// create a new taxonomy
register_taxonomy(
'people',
'post',
array(
'label' => __( 'People' ),
'rewrite' => array( 'slug' => 'person' ),
'capabilities' => array(
'assign_terms' => 'edit_guides',
'edit_terms' => 'publish_guides'
)
)
);
}
add_action( 'init', 'people_init' );
So, if you called it "team-category", you would then use that in the 'taxonomies' array in your post type.
Here's a more specific example:
function tr_create_my_taxonomy() {
register_taxonomy(
'team-category',
'team',
array(
'label' => __( 'Category' ),
'rewrite' => array( 'slug' => 'team-category' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'tr_create_my_taxonomy' );
本文标签: Create category only for custom post type
版权声明:本文标题:Create category only for custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745455828a2659096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论