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
? ) – Tom J Nowell ♦ Commented Dec 16, 2019 at 16:44tag
taxonomy – Tom J Nowell ♦ Commented Dec 16, 2019 at 19:52