3

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.

2
  • Do they need to be the same taxonomy? Simplest solution would be to have two different taxonomies: post_taxonomy and location_taxonomy, for example. Mar 18, 2018 at 16:02
  • @JacobPeattie yes I have thought of separating them but what I am trying to do (though I know it wont be simple on my part) is to keep is simple for the user because the post and events post types share common locations and it would be better if when a location is added, it will automatically be available for both posts and events. Mar 18, 2018 at 16:04

1 Answer 1

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.

4
  • 1
    I think she was asking about having separate indexes for each post type, not different templates for individual posts on the one index. Mar 18, 2018 at 16:17
  • That wouldn't be possible. What if a term is assigned to both post types?
    – Johansson
    Mar 18, 2018 at 16:19
  • Thanks Jack, @JacobPeattie is right. I am aiming to have a separate archive pages for the terms for each post type. Mar 18, 2018 at 16:19
  • 1
    You should create a new taxonomy. A term can be assigned to multiple post types in your case, which can break the code. @Jeda
    – Johansson
    Mar 18, 2018 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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