Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called freebies. This custom post type has its own taxonomy with the "normal" categories from wordpress, (which are child-categories from freebies) and own custom taxonomy used as tags (called freebie-tags)

I have managed to have own templates for the freebies: archive-freebies.php and the posts from child categories of freebies are displayed in category-freebies.php. The tags from freebies are displayed in the template taxonomy-freebie-tags.php

Now when the visitor clicks on a category in freebies, he sees the posts in this category, and when clicking on a tag in freebies, he sees those posts with the tag.

I'd like to combine these two, so that when the visitor is in a child-category, and clicks on a tag (they are displayed on the sidebar as a cloud) he will see a template which shows only those posts which are a) in the child-category and b) have the specific tag.

The other way round (also when viewing posts with a certain tag and clicks on category) is not neccessary.

So this question is

  1. How to tell wordpress that it has to use a another template like category-freebies-taxonomy-freebies-tag.php

  2. how to build the links for the cloud that they show posts only from this specific child category where the user is now, and tagged with this tag?

Sorry if here is no efford from my side, but I had so much difficulties with showing the appropriate templates for so far, that I have no idea where to go further with this. I searched here and google also, but did not found anything, since this is not related to normal post, rather to custom post type...

Thx!

share|improve this question

1 Answer 1

Maybe change the permalinks for the tags in the sidebar to point to the category page they're already viewing then pass the tag as a url parameter. If the parameter is set use pre_get_posts to merge the tag into the main query so it filters by both the category and tag.

Something along these lines

function filter_by_tag_too( $query ) {
  if ( isset( $_GET['tag'] ) ) {
    $query->set( 'tag', $_GET['tag'] );
  }
}
add_action( 'pre_get_posts', 'filter_by_tag_too' );
share|improve this answer
    
Thank you very much, this sound really logical! I think I add a filter/query so that the category pages show also only the tags related to that category (they are already related to the freebies taxonomy) I will try this with your answer –  Owl Jun 7 at 15:44
    
Did this work out for you? –  Joey Yax Jun 11 at 22:09
    
Sorry Joey I have not time to try at the moment, but I will let you know as soon as I could try it! –  Owl Jun 13 at 6:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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