Getting the Intersection of Two Custom Taxonomy Terms for a Custom Post Type?

As of v1.3, the Query Multiple Taxonomies plugin works great with WP_Query. Your original args work as is.

$args = array(
'post_type' => 'portfolio',
'numberposts' => -1,
'project_type' => 'A',
'package' => 'A'
);

Then make a new query and check it:

$foo = new WP_Query($args);
var_dump($foo->posts);

I tested this on my own custom taxonomy setup, and it only returned posts which matched both terms in the query.

Another convenient method of grabbing multiple taxonomy terms with QMT is building simple URL queries:

site.com/?post_type=portfolio&package=foo&project=bar

I’ve used this method with the add_query_args() function to create links on a page that modify the current query, refining it by adding additional terms and taxonomies. The syntax also works great with a search input, as multiple words in the input field are posted as foo+bar, which works great with QMT:

site.com/?post_type=portfolio&project=alpha&colors=red+blue+green

Which returns only posts that meet all these criteria – Type: Portfolio / Project: Alpha / Colors: red + blue + green

Leave a Comment