Is it possible to have an index page for taxonomy term for each custom post type it is assigned to?

I currently have a setup where I have a custom taxonomy that is link to the WordPress post post type and another custom post type.

Since the custom taxonomy is assigned to the two post types mentioned, the taxonomy term index page displays all the post assigned that that term regardless of the custom post type it was added to.

So right now, I have the location taxonomy assigned to the post and events post types.

The posts and events archive pages have different template views. What I am trying to figure out if it is possible to have an index page for the location taxonomy where it will be able to display the posts assigned to a location and separate it according to the custom post type.

So if I have the taxonomy location terms Asia and Europe, I would like to find a way to have an archive page for the Asia and Europe posts for the post and events types separately.

Hope this makes sense.

1 Answer
1

A simple method would be to create a archive template file for the location taxonomy, and then include the proper inner-template for each post type.

First, create a PHP file in your theme’s root folder, named taxonomy-location.php. Then, you can use get_post_type() insider this template the include the proper template:

get_template_part( 'templates', get_post_type() . '-content' );

Now, you can create 2 different PHP files named template-content.php and template-location-content.php. Feel free to edit the to suit your styles.

Leave a Comment