[wp-hackers] Query for Multiple Custom Taxonomies

Mike Schinkel mikeschinkel at newclarity.net
Mon Oct 4 22:01:47 UTC 2010


On Oct 4, 2010, at 1:22 PM, Curtis McHale wrote:
> Use Case:
> 
> Music site with 'genre' as a hierarchical taxonomy. Each show may have multiple genres associated with it.
> 
> Currently query_posts(); doesn't support putting multiple slugs into the query so I could grab shows of the same genre that the user might be interested in. Looking around you have to query the database directly.
> 
> There should be a query parameter of $taxonomy_id that lets you put multiple ids into the query just like cat_id does.

Here's an example [1] showing you how to add a filter on posts_where to support a "tax_terms" parameter in the format of "{$taxonomy1}:{$term1},{$taxonomy2}:{$term2},...{$taxonomyN}:{$termN}", i.e.:

$result = new WP_Query('post_type=show&tax_terms=genre:grunge,genre:alternative');	
foreach($result->posts as $post) {
	echo "{$post->post_title}\n";
}

Hope this helps.

-Mike
[1] http://gist.github.com/610526


More information about the wp-hackers mailing list