0

I was wondering if there was an easy way to display posts from a tag from a specific category. In other words, if I have Category1, Category2, and Category3, and these all have posts with a tag 'topic1' what's the easiest way to display the posts containing tag 'topic1' from only one of the above mentioned categories at a time rather than from the entire site at once.

Am I wrong in assuming this is an easy task?

2
  • Do you want to create a custom page template or are you taling about the default tag.php and category.php templates Oct 14, 2014 at 6:46
  • @PieterGoosen I think I'm going to have to create a custom page template.
    – dwyrin
    Oct 15, 2014 at 7:58

1 Answer 1

0

From your comments, you opted for a custom page template. Based on that, you can simply perform a custom query to retrieve posts that belongs to a certain tag and category

I tend to make use of a tax_query using WP_Query when you quering posts from more than one taxonomy. It is more flexible, specially if you need to exclude children from hierarchical taxonomies

You can construct your query as follow

$args = array(
   'post_type' => 'post',
   'tax_query' => array(
      'relation' => 'AND',
      array(
         'taxonomy' => 'category',
         'field'    => 'slug',
         'terms'    => 'SLUG OF THE CAT',
      ),
      array(
         'taxonomy' => 'post_tag',
         'field'    => 'slug',
         'terms'    => 'SLUG OF THE TAG',
      ),
   ),
);
$query = new WP_Query( $args );

You can visit the links provided to learn how to construct your loop using WP_Query

1

Your Answer

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

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