[wp-hackers] advanced taxonomy queries
chip at chipbennett.net
Fri Dec 21 12:28:39 UTC 2012
You're right, Otto. That's what I get for answering questions at 11:30 at
Just change my answer to use 'category__and', instead of 'category__in'.
The funny thing is, I almost added that as an addendum to say,
"category__in will give you foo OR bar, and category__and will give you foo
On Fri, Dec 21, 2012 at 6:33 AM, Otto <otto at ottodestruct.com> wrote:
> Ignore the previous answers by Ian and Chip, I think they missed the
> "AND" part of the question.
> The correct answer is to add an operator to your array.
> $myquery['tax_query'] = array(
> 'taxonomy' => 'category',
> 'terms' => array('foo', 'bar'),
> 'field' => 'slug',
> 'operator' => 'AND',
> You may also want to add 'include_children' => false, if you don't
> want the category searcher to pick up posts that are in child
> categories of foo and bar as well.
> Note that there is a shortcut version of this called category__and,
> which accepts the ID values of the categories only.
> On Thu, Dec 20, 2012 at 10:04 PM, Haluk Karamete
> <halukkaramete at gmail.com> wrote:
> > In this query, we get the posts in the foo cat OR the bar cat
> > $myquery['tax_query'] = array(
> > array(
> > 'taxonomy' => 'category',
> > 'terms' => array('foo', 'bar'),
> > 'field' => 'slug',
> > ),
> > );
> > query_posts($myquery);
> > how do we change in the above snippet it so that we get the posts that
> > are in both categpories? That is both in the foo cat *AND* in the bar
> > cat?
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers