WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to show posts having both a specified category and tag applied (4 posts)

  1. gendem
    Member
    Posted 4 years ago #

    Hi there

    I am trying to create a modification to the post loop to show all posts having both a specified category and a specified tag applied. In other words, each post shown must have both applied; they can have more than both applied, but they must have at least both.

    By way of example, if I ask for posts in the "recipe" category tagged as "pie," I'm happy to get posts in the "recipe" category tagged as both "pie" and "dessert," but not posts in the "recipe" category tagged only with "dessert."

    I found this in the codex that seems to handle a multiple-category AND request:

    query_posts(array('category__and' => array(2,6)));

    and this to handle a multiple-tag AND request:

    query_posts('tag=bread+baking+recipe');

    Is there a way to adopt/combine this to show posts for a given category and tag? Or would it be easier to just use only categories or tags, not both? Note that this is a new blog, empty of content, and so structural decisions like this are fine atm.

    As a second part to the question, can anyone suggest a way to create a call to this using a link so that I don't have to create a static page for each result?

    ...Mike

  2. vtxyzzy
    Member
    Posted 4 years ago #

    I just helped jeremyduffy find a problem in query_posts with a similar request here. Turns out that query_posts apparently can't handle simultaneous selections of tags and categories. You will have to roll your own query.

    I am not sure what you want for the second request. Can you clarify?

  3. gendem
    Member
    Posted 4 years ago #

    I'll just use categories then until this is sorted out.

    As for the second part, this post gave me the answer :)

    Thanks

    ...Mike

  4. vtxyzzy
    Member
    Posted 4 years ago #

    Great! Please mark this topic Resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic