I have a WP_Query that outputs featured products. For each product I would also like to link to the category of that product, but I'm not sure how.
I think this is close to being my answer, but I'm not sure how to put it all together. How to get category link without a database query
My query so far is:
<?php
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
'posts_per_page' => 8
);
$loop = new WP_Query( $args ); ?>
<ul class="product-list">
<?php while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class="product-list__item">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>"
<?php the_title(); ?>
</a>
Link to the product category here!
Any help is much appreciated.