Associate Taxonomies Across Post Types

Let’s say I’ve created two custom post types, one called post_type_author and another called post_type_book. In each of these two custom post types, I’ve created a non-hierarchical taxonomy for tags.

What is the best way to associate these two custom post type’s taxonomies?

Read More

Also, if I wanted to link these two along with the default “post” post type, how would that be done?

What I want is to use the same non-hierarchical taxonomy “tags” for each of the three post types, so that a tag permalink called “Chicago”, for example, will pull a post called “Saul Bellow” from the “post_type_author” custom post type.

It should also pull a post called “Great Chicago Landmarks” from the “post_type_book” custom post type tagged “Chicago” AND another post from the default “post” post type that was also tagged “Chicago”.

Do I create two additional taxonomies and link them to the “post” post type taxonomy? Or is there a better way?

I hope this makes sense and thanks very much.

Related posts

Leave a Reply

1 comment

  1. Create one taxonomy and share it across all post types. You won’t be able to have the same slug across multiple taxonomies anyway, they have to be unique due to the way they’re stored in the database.

    You can use the built in tags taxonomy with your custom post type by setting

    'taxonomy' => array('post_tag')
    

    when you register your custom post type, or you can add a custom taxonomy to regular posts (as well as your custom types) when you register your taxonomy by passing an array for $object_type:

    array('post', 'post_type_author', 'post_type_book')