php - List custom post types with custom taxonomy category assigned to them
one text
Solution:
You might need to add the relation
to your args.
$args = array(
'post_type' => 'products',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_category',
'terms' => $category,
'field' => 'slug',
),
),
);
Also, check:
- Is the post type spelled correctly (i.e. Are you sure it's
products
and notproduct
?) - In your first query you have
product_category
but in your second query you haveproduct-category
. Should it be a hyphen or an underscore? - Is the value returned by
$category
valid?