You're initializing the $liquor_brands
array, running it through a foreach
loop that does nothing, then echoing out the slug of $liquor_brand
outside of the foreach
loop. $liquor_brand
is going to be set to the last item in the $liquor_brands
array since the whole array was iterated over. Long story short, you should do the echoing inside of the foreach
loop:
<?php
$liquor = new WP_Query( array(
'post_type' => 'product',
'product_cat' => 'liquors',
'meta_query' => array(
array(
'key' => '_stock_status',
'value' => 'instock'
)
)
) );
if ( $liquor->have_posts() ) : while ( $liquor->have_posts() ) : $liquor->the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="three columns product-post">
<?php
$liquor_brands = get_terms( 'pa_liquor-brands' );
foreach ( $liquor_brands as $liquor_brand ) {
echo $liquor_brand->slug;>slug . ' ';
}
?>
</div>
<?php wp_reset_postdata(); ?>
<?php endwhile; else: ?>
<?php //error message ?>
<?php endif; ?>
<?php wp_reset_query(); ?>