Query WordPress Posts in a Custom Post Type and Custom Taxonomy

Here is a quick tip on querying posts that belongs to a custom post type and category / custom taxonomy.

Actually, I ran into this problem while working with Easy Digital Downloads plugin.

I wanted to query a list of products in a given category. I thought the query will be easy to construct but I was wrong.

Note: all EDD products are actually posts of a download custom post type and the category, a custom taxonomy with name download_category.

Below is the code I used in querying a list of EDD products or posts in an EDD category with slug login.


$args = array(
	'post_type' => 'download',
	'tax_query' => array(
		array(
			'taxonomy' => 'download_category',
			'field' => 'slug',
			'terms' => 'login'
		),
	),
);

$product_query = new WP_Query($args);

Check out the WP_Query documentation for more information.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address