There is a cycle that outputs products
<?php
$args = array('post_type' =>
'product');
$loop = new WP_Query($args);
foreach ($loop->posts as $have_post) : ?>
<div class="swiper-slide">
<a href="
<?php
$permalink = get_post_permalink($have_post->ID);
echo $permalink;
?>
" class="goods__item">
<div class="goods__text">
<?php
echo $have_post->name; ?>
</div>
<div class="goods__img">
<?php
echo get_the_post_thumbnail($have_post->ID, 'full', array('alt' => $have_post->post_title, 'data-product_id' => $have_post->ID)); ?>
</div>
<div class="goods__name"><?php echo $have_post->post_title; ?></div>
<div class="goods__price">
<?php
$price = get_post_meta($have_post->ID, '_price', true);
echo $price; ?> руб.
</div>
</a>
</div>
<?php endforeach; ?>
Need to show the category of current product here. I cant get the category. Please help
<div class="goods__text"><?php echo $have_post->name; ?></div>
2
Answers
You could use
get_the_terms
to get the correct terms. I believe it’sproduct_cat
the correct taxonomy.Try get_the_category( $post->ID );