0
votes

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>
Does that object have a name property? If you output the entire object (print_r($have_post);) what does it contain? - David
Welcome to SO! Please read how to ask and edit your question with more details. What is output if you do var_dump($have_post); die() inside of your loop? Is there event a category or categories key on the $have_post object? - WOUNDEDStevenJones