admin管理员组文章数量:1410705
I have several post type (animal, science, car), I want all these posts type to use the same Wordpress default tag. exemple of car post type :
// custom post type
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'car',
array(
'labels' => array(
'name' => __( 'Car' ),
'add_new_item' => 'Ajouter une voiture',
'edit_item' => 'Modifier une voiture',
'new_item' => 'Ajouter une voiture',
'singular_name' => __( 'car' )
),
'public' => true
)
);
register_taxonomy( 'categorycar', 'car', array( 'hierarchical' => true, 'label' => 'Category voiture', 'query_var' => true, 'rewrite' => true ) );
i use a custom category different of each post type and i want use default tag wordpress for all post type.
Thanks for your help.
I have several post type (animal, science, car), I want all these posts type to use the same Wordpress default tag. exemple of car post type :
// custom post type
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'car',
array(
'labels' => array(
'name' => __( 'Car' ),
'add_new_item' => 'Ajouter une voiture',
'edit_item' => 'Modifier une voiture',
'new_item' => 'Ajouter une voiture',
'singular_name' => __( 'car' )
),
'public' => true
)
);
register_taxonomy( 'categorycar', 'car', array( 'hierarchical' => true, 'label' => 'Category voiture', 'query_var' => true, 'rewrite' => true ) );
i use a custom category different of each post type and i want use default tag wordpress for all post type.
Thanks for your help.
Share Improve this question edited Dec 16, 2019 at 16:22 admindunet asked Dec 16, 2019 at 16:14 admindunetadmindunet 11 bronze badge 3 |1 Answer
Reset to default 0Use taxonomies
parameter when registering custom post type:
register_post_type( 'car',
[
'labels' => [ /* ... */ ],
'public' => true,
'taxonomies' => [ 'post_tag', 'categorycar' ],
]
);
Or, after registering post types, use register_taxonomy_for_object_type()
function.
register_post_type( 'animal', /* ... */ );
register_post_type( 'science', /* ... */ );
register_taxonomy_for_object_type( 'post_tag', 'animal' );
register_taxonomy_for_object_type( 'post_tag', 'science' );
本文标签: Tag for custom post type
版权声明:本文标题:Tag for custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744898945a2631230.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
tag
? ) – Tom J Nowell ♦ Commented Dec 16, 2019 at 16:44tag
taxonomy – Tom J Nowell ♦ Commented Dec 16, 2019 at 19:52