V
V
Vlad Lisovets2019-01-29 23:12:14
WordPress
Vlad Lisovets, 2019-01-29 23:12:14

Duplicate woocommerce cycle?

Hi guys!
I can't figure out what the problem is. I display several cycles on the page to display products from different categories, each group of products in its own block. But I came across the fact that regardless of whether I specify the taxonomy slug or not, all blocks display the same products mixed from different categories. Please tell me where I made a mistake.

Example of the first request to one category

<?php
$params5 = array('post_type' => 'product',
        'posts_per_page' => 2,
        'tax_query' => 'aksessuary-i-rashodnye-materialy');
$wc_query5 = new WP_Query($params5);
?>
<?php if ($wc_query5->have_posts()) : ?>
     <?php while ($wc_query5->have_posts()) :
                $wc_query5->the_post(); ?>
<div class="item">
<?php the_post_thumbnail('tglavnaya'); ?>
 <h2><?php the_title(); ?></h2>
 <h4><span class="tooltip">Подробнее<span class="tooltip-text"><?php the_excerpt(); ?></span></span></h4>
 <h5> <? echo $product->get_price_html(); ?></h5>
 <div class="g2011164 zakazat">Заказать</div>
</div>
  <?php endwhile; ?>
     <?php wp_reset_postdata(); ?>
    
    
     <?php endif; ?>

Example of the second block and another category of goods
<?php
$params4 = array('post_type' => 'product',
        'posts_per_page' => 20,
        'tax_query' => 'pechati-v-metallicheskom-korpuse');
$wc_query4 = new WP_Query($params4);
?>
<?php if ($wc_query4->have_posts()) : ?>
     <?php while ($wc_query4->have_posts()) :
                $wc_query4->the_post(); ?>
<div class="item">
<?php the_post_thumbnail('tglavnaya'); ?>
 <h2><?php the_title(); ?></h2>
 <h4><span class="tooltip">Подробнее<span class="tooltip-text"><?php the_excerpt(); ?></span></span></h4>
 <h5> <? echo $product->get_price_html(); ?></h5>
 <div class="g2011164 zakazat">Заказать</div>
</div>
  <?php endwhile; ?>
     <?php wp_reset_postdata(); ?>
    
    
     <?php endif; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2019-01-29
@azerphoenix

What if these lines are:
change to:

'tax_query' => array(
  array(
    'taxonomy' => 'product_cat',
    'field'    => 'slug',
    'terms'    => 'pechati-v-metallicheskom-korpuse'
  )
)

PS If you want to display products beforehand dividing them into categories on one page, then you can not create several cycles, but use 2 nested cycles. The first one gets the taxonomy term, and the second one gets the term products.
Similar example - https://gist.github.com/DevinWalker/6fb2783c05b46a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question