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.

  • Do they need to be the same taxonomy? Simplest solution would be to have two different taxonomies: post_taxonomy and location_taxonomy, for example. – Jacob Peattie Mar 18 '18 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. – Jeda Dragon Mar 18 '18 at 16:04
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.

  • 1
    I think she was asking about having separate indexes for each post type, not different templates for individual posts on the one index. – Jacob Peattie Mar 18 '18 at 16:17
  • That wouldn't be possible. What if a term is assigned to both post types? – Jack Johansson Mar 18 '18 at 16:19
  • Thanks Jack, @JacobPeattie is right. I am aiming to have a separate archive pages for the terms for each post type. – Jeda Dragon Mar 18 '18 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 – Jack Johansson Mar 18 '18 at 16:21

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.