• Hi, is there any way to retrieve all and only those posts in category 2 and 3 but not those only in 2 or only in 3?

    I’ve tried it with query_posts, but the function doesn’t accept more than 1 category id.

    I’ve also found the taxonomy write up at boren.nu, that has some information about the “category__and” function in WP 2.3, but it says I’d have to write a plugin to use it.

    https://boren.nu/archives/2007/10/01/taxonomy-intersections-and-unions/

    If the latter is necessary, does anyone have an idea where to find any documentation for the $wp->set_query_var() function? I could not find any.

    Thanks for every small hint!

    YMS

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    I think this will work.

    <?php query_posts(array('category__and'=>array(2,3)); ?>

    Thread Starter youngmicroserf

    (@youngmicroserf)

    So cool! Thanks Otto!!! How do you know this? Is there some kind of documentation about this? Or did you write the function ;). Either way, thanks so much. Do you think it would make sense to include this in the query_posts documentation? I’ll happily do that when I’m done with the implementation…

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    I figured it out by reading the code. It’s not that tricky.

    Hey Otto,

    What would you suggest I do if we took this ‘dual category query’ one step further, and I wanted to echo the links of the dual categories on the sidebar.

    For example, a user clicks on a category, that id is then passed to the function, and then the function spits out the ‘dual category links’ on the sidebar. So when a user, already on a category template, then clicks on the ‘dual category link,’ they will then see all of the posts filed within both of those categories.

    I guess my question really comes down to, how would I best go about gathering an array of categories that have a relationship (are both connected to a post) to a given category?

    Thanks.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You can make links that show multiple categories, I think.
    https://example.com/blog/?cat=2+3
    Might work.

    As for how you’d associate categories, the only way I can think to do it would be some custom SQL code.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to retrieve only posts that are in two specific categories (AND, not OR)’ is closed to new replies.