P
P
Pavel2016-04-02 19:31:58
WordPress
Pavel, 2016-04-02 19:31:58

Why is woocommerce pagination not working?

Pagination on sale page not working. The point is this. I took the standard archive-product.php, created a template for a page with a selection of goods for sale from it. Everything is displayed and works except for pagination. The url changes when switching pages, but the first 20 products are still displayed, at least on the 2nd, at least on the 4th page. And in the page list "current" always remains the first. Here is the template code:

<?php
/**
 * Template Name: page-sale
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
get_header( ); ?>
    <main>
        <div class="container container-main">
            <div class="row">
                <div class="col-md-9">
                    <?php
                    do_action( 'woocommerce_before_main_content' );
                    ?>
                    <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
                        <h1 class="page-title">Распродажа!</h1>
                    <?php endif; ?>
                    <?php
                    do_action( 'woocommerce_archive_description' );
                    $args = array(
                        'post_type'      => 'product',
                        'meta_query'     => array(
                            'relation' => 'OR',
                            array( // Simple products type
                                'key'           => '_sale_price',
                                'value'         => 0,
                                'compare'       => '>',
                                'type'          => 'numeric'
                            )
                        )
                    );
                    query_posts( $args );
                    ?>
                    <?php if ( have_posts() ) : ?>
                        <?php
                        do_action( 'woocommerce_before_shop_loop' );
                        ?>
                        <?php woocommerce_product_loop_start(); ?>
                        <?php woocommerce_product_subcategories(); ?>
                        <?php while ( have_posts() ) : the_post(); ?>
                            <?php wc_get_template_part( 'content', 'product' ); ?>
                        <?php endwhile; // end of the loop. ?>
                        <?php woocommerce_product_loop_end(); ?>
                        <?php
                        do_action( 'woocommerce_after_shop_loop' );
                        ?>
                    <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
                        <?php wc_get_template( 'loop/no-products-found.php' ); ?>
                    <?php endif; ?>
                </div>
                <?php
                do_action( 'woocommerce_after_main_content' );
                ?>
                <?php get_sidebar(); ?>
            </div>
        </div>
    </main>
<?php get_footer( ); ?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel, 2016-04-26
@Palych_tw

Added to the array 'paged' => $paged,everything worked

I
Igor Vorotnev, 2016-04-03
@HeadOnFire

You need the Bart Simpson method.
Take a pack of A4 paper, a pen, sit down at the table, and start writing on the first sheet, one by one, from top to bottom of the sheet and on the back, the phrase "I WILL NEVER USE THE QUERY_POSTS () FUNCTION AGAIN" ...
I am more I don't know how to reach people. This topic has been talked about hundreds of thousands of times, Google is simply full of this warning, but people continue to step on the rake.
In your case, read about the pre_get_posts hook.

S
Stas Densis, 2018-06-13
@deenween

There is a plugin that solves this problem: https://ru.wordpress.org/plugins/on-sale-page-for-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question