0

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.

3
  • So you want to add multiple CPT's to an existing taxonomy? ( in this case tag? )
    – Tom J Nowell
    Dec 16 '19 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
    Dec 16 '19 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
    Dec 16 '19 at 19:52
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' );
2
  • its work, thank you.
    – admindunet
    Dec 16 '19 at 18:40
  • @admindunet if this answers the question could you mark it as the correct answer by clicking the check/tick under the voting controls? That way nmr gets points
    – Tom J Nowell
    Dec 16 '19 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.