Answer the question
In order to leave comments, you need to log in
How to fix wocommerce pagination?
There is a code for displaying goods, for example, 2 products per page, then I want to do pagination, but pagination does not work, the code itself appears and you can see 1 2 3 Next, but when you just click on the main page, it throws how this can be fixed, please tell me.
global $post, $wp_query;
$query_args = array(
'post_type' => 'product', // указываем, что выводить нужно именно товары
'posts_per_page' => 2, // количество товаров для отображения
'orderby' => 'date', // тип сортировки (в данном случае по дате)
'product_cat' => $sort,
);
$query = new WP_Query( $query_args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<div class="product-main">
<div class="product-img"> <a href="<?php echo get_permalink(); ?>" class="avatar"><img class="responsive-img" src="<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
echo $thumb_url[0];
?>" alt=""></a>
</div>
<div class="product-title"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></div>
<div class="product-id"><?php echo $product->get_id() ?></div>
<div class="product-size">Размер: <?php echo $product->get_attribute('size'); ?> см.</div>
<div class="product-price__box">
<div class="product-price">Цена: <?php echo $product->get_price_html(); ?> грн.</div>
</div>
<div class="product-art">Артикул: <?php echo $product->get_sku(); ?></div>
<div class="product-button">
<button class="fast-buy-green"><a onclick="tobasket(<?php echo $product->get_id();?>)">В корзину</a></button>
<button class="fast-buy">Быстрая покупка</button>
</div>
</div>
<?php
}
wp_reset_postdata();
$temp_query = $wp_query;
$wp_query = null;
$wp_query = $query;
the_posts_pagination();
$wp_query = null;
$wp_query = $temp_query;
};?>
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