I have a custom post type called "categories" and it's slug is "category". I have various categories like:
- Beauty
- Makeup
- Skincare
- Tech
I have these categories in a CPT called "Products". I want to display only those posts that match with a subcategory. For example, I want to display only those posts from CPT "Products" that have "Makeup" checked in categories custom taxonomy. I have tried the following code:
$args= new WP_Query( array(
'post_type' => 'Products',
'tax_query' => array(
array (
'taxonomy' => 'categories',
'field' => 'slug',
'terms' => 'Beauty',
)
),
) );
if($args->have_posts()):
while ($args->have_posts()):$args->the_post();
echo get_field('name');
endwhile;
endif;
But this code obviously displays posts that have category checked as "Beauty". It doesn't check for subcategory. Can anyone help me out with this? Any modification to the current code would be helpful as well. Thanks!