WordPress.org

Make WordPress Core

Opened 11 years ago

Last modified 6 years ago

#9951 closed enhancement

Add [taxonomy]__in, [taxonomy]__not_in to wp_query — at Initial Version

Reported by: joehoyle Owned by: filosofo
Milestone: Priority: high
Severity: normal Version: 2.8
Component: Query Keywords: needs-patch early
Focuses: Cc:
PR Number:

Description

Currently it's not possible to query for multiple custom taxonomy terms using query_posts the same way you can do tagin, categoryin, tagnot_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 tagin 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 tagin, categoryin and all of those are no different, the patched lines I wrote could replace all those hardcoded statements fairly easily.

Change History (1)

@joehoyle
11 years ago

Patch to allow [custom taxonomy]in in wp_query

Note: See TracTickets for help on using tickets.