Answer the question
In order to leave comments, you need to log in
Why is the output of Woocommerce products duplicated in the loop?
Hello. On the main page there are several cycles for displaying various types of products and there is a cycle in which products are duplicated when outputting, its code is given below. It is specified to display 9 products, and 18 products are displayed, 2 of the same. I don’t understand what could be the problem. others work without duplication, this cycle is displayed in the slider (if this may be the reason), although I tried to display without the slider and the duplication did not disappear. Tell me please.
<?php
// задаем параметры выборки в массиве
$args = array(
'post_type' => 'product',
'posts_per_page' => 9,
);
// запрос
$query = new WP_Query( $args );
?>
<?php if ( $query->have_posts() ) : ?>
<section class="section section__four">
<div class="container">
<div class="row">
<div class="col-12">
<h2><?php _e('Новые игры', 'accs'); ?></h2>
<div class="slider__wrapper">
<div class="slider__progress">
<!-- цикл -->
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php wc_get_template_part( 'content', 'newproduct' ); ?>
<?php endwhile; ?>
<!-- конец цикла -->
<?php wp_reset_postdata(); //очищаем результат запроса?>
</div>
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</div>
</div>
</section>
<?php else : ?>
<p><?php esc_html_e( 'Ничего не найдено.' ); ?></p>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question