Support » Fixing WordPress » Display blog posts from specific category AND tag

  • I know it’s easy to display blog posts from EITHER a category or tag. However, I’d like WordPress to display content that is posted in a specific category AND with a specific tag.

Viewing 12 replies - 1 through 12 (of 12 total)
  • esmi


    Forum Moderator

    Thank-you for this. I don’t really know how to program so how do I combine the codes:

    Multiple category handling:
    query_posts(array('category__and' => array(2,6)));


    Multiple tag handling:
    query_posts(array('tag__and' => array('bread','baking'));

    So that the above would return only posts in both categories 2 and 6, AND tagged with both bread and baking?


    I am also looking for a similar solutioin.
    I need to have links in my sidebar like “Bread” that should take users to the archive page showing posts under category “baking” and tagged with “Bread”.

    Is there anything like


    I’m still looking for the same solution you were looking for. Linking to a URL just like you state in your example!

    I haven’t figured it out yet 🙁 Did you?!

    @amplifiedshock try this:

    $args = array(
       'category__and' => array(2,6),
       'tag__and' => array('bread','baking')

    @nims & dikkevandale: make a template using the query you want and post a link to a page using that template. See the Codex Stepping Into Templates

    @vtxyzzy, I can do that easily 🙂 No problem, it works.

    But I want to load it with variables, because the combinations are endless. That would let me make more than 100+ templates. If it could be solved with a variable enabled query, I don’t have to.

    @dikkevandale, are you OK with using Custom Fields to supply the variables? If so, you could use code like this (UNTESTED):

    <?php $my_cats = explode(',',get_post_meta($post->ID,'categories-to-show',TRUE));
    $my_tags = explode(',',get_post_meta($post->ID,'tags-to-show',TRUE));
    $args = array(
       'category__and' => $my_cats,
       'tag__and' => $my_tags

    where the Custom Field ‘categories-to-show’ is a comma separated list of category ids, and ‘tags-to-show’ is a comma separated list of tags.

    That way, one template would serve all pages.

    Just a thought but I believe tag__and requires tag IDs.

    @michaelh, you are correct. Thanks for the info.

    So we are back to square one !

    Not at all, is there a particular reason you can’t use IDs in place of names?

    can someone help pls …. I hv still not found the answer

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Display blog posts from specific category AND tag’ is closed to new replies.