[wp-trac] [WordPress Trac] #9951: Add [taxonomy]__in, [taxonomy]__not_in to wp_query
WordPress Trac
wp-trac at lists.automattic.com
Mon Aug 16 10:22:40 UTC 2010
#9951: Add [taxonomy]__in, [taxonomy]__not_in to wp_query
-------------------------+--------------------------------------------------
Reporter: joehoyle | Owner: MarkJaquith
Type: enhancement | Status: assigned
Priority: high | Milestone: Future Release
Component: Query | Version: 2.8
Severity: normal | Keywords: needs-patch early
-------------------------+--------------------------------------------------
Description changed by scribu:
Old description:
> Currently it's not possible to query for multiple custom taxonomy terms
> using query_posts the same way you can do tag__in, category__in,
> tag__not_in etc. I propose wp_query is extended to support querying by
> multiple custom taxonomy terms and also multiple custom taxonomies and
> terms.
>
> For example, to get all posts that are in my 'Microsoft' term in the
> 'company' tax:
>
> {{{
> query_posts( array( 'company__in' => array( 5 ) ) ) //5 is the term_id
> for Microsoft
> }}}
>
> Multiple taxs with multiple terms:
>
> {{{
> query_posts( array(
> 'company__in' => array( 5, 10 ),
> 'people__in' => array( 11, 12, 13 ),
> ));
> }}}
>
> Basically: [tax]__in, [tax]__not_in and [tax]__slug_in should all work,
> in conjunction with tag__in etc.
>
> I have written a patch that implements this, currently [tax]__in,
> [tax]__not_in, but [tax]__slug_in will be an easy addition.
>
> As tag__in, category__in and all of those are no different, the patched
> lines I wrote could replace all those hardcoded statements fairly easily.
New description:
Currently it's not possible to query for multiple custom taxonomy terms
using query_posts the same way you can do {{{tag__in}}},
{{{category__in}}}, {{{tag__not_in}}} etc. I propose wp_query is extended
to support querying by multiple custom taxonomy terms and also multiple
custom taxonomies and terms.
For example, to get all posts that are in my 'Microsoft' term in the
'company' tax:
{{{
query_posts( array( 'company__in' => array( 5 ) ) ) //5 is the term_id for
Microsoft
}}}
Multiple taxs with multiple terms:
{{{
query_posts( array(
'company__in' => array( 5, 10 ),
'people__in' => array( 11, 12, 13 ),
));
}}}
Basically: {{{[tax]__in}}}, {{{[tax]__not_in}}} and {{{[tax]__slug_in}}}
should all work, in conjunction with {{{tag__in}}} etc.
I have written a patch that implements this, currently {{{[tax]__in}}},
{{{[tax]__not_in}}}, but {{{[tax]__slug_in}}} will be an easy addition.
As {{{tag__in}}}, {{{category__in}}} and all of those are no different,
the patched lines I wrote could replace all those hardcoded statements
fairly easily.
--
--
Ticket URL: <http://core.trac.wordpress.org/ticket/9951#comment:25>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list