I want to use Advanced Custom Fields to determine from which category products will be shown. The ACF field gives the ID of the category and from that I can get the slug. I can't get it to work in the array though, and so it shows all products on the page. Does anyone have suggestions or ideas why it's not working? Thanks in advance!
$term_id = get_field('kies_product_categorie'); //Get category id
$term = get_term_by('id', $term_id, 'product_cat'); //Get terms from given category
$args = array(
'post_type' => 'product',
'posts_per_page' => 9,
'orderby' => 'date',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => $term->slug //Slug of given category
)
)
);