Skip to content

Instantly share code, notes, and snippets.

@mennwebs
Created April 12, 2018 06:12
Show Gist options
  • Save mennwebs/f9e1907316b7c20f31e888e7e48db179 to your computer and use it in GitHub Desktop.
Save mennwebs/f9e1907316b7c20f31e888e7e48db179 to your computer and use it in GitHub Desktop.
ACF - Show product by Brand and Product_cat Taxonomy
<?php
if( have_rows($brand_slug) ):
$i = 1;
while( have_rows($brand_slug) ):
the_row();
$cat = $brand_slug . '-cat';
$term = get_sub_field($cat);
?>
<div class="tab-products">
<?php
$args = array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_brand',
'field' => 'slug',
'terms' => $brand_slug
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $term->slug
),
),
'post_type' => 'product',
'posts_per_page' => 6
);
$the_query = new WP_Query( $args );
?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'template-parts/featured', 'product' ); ?>
<?php endwhile; wp_reset_postdata(); ?>
</div>
<?php
endwhile;
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment