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
  • So you want to add multiple CPT's to an existing taxonomy? ( in this case tag? ) – Tom J Nowell Commented Dec 16, 2019 at 16:44
  • no, i want, if i create a post (car or science or animal) i can select tag from the tags I created by default (under default post, left menu admin WP). – admindunet Commented Dec 16, 2019 at 17:43
  • hmmm judging from the answer you got and saying it worked, you did indeed want to add multiple CPT's to the tag taxonomy – Tom J Nowell Commented Dec 16, 2019 at 19:52
Add a comment  | 

1 Answer 1

Reset to default 0

Use 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