简体   繁体   中英

WooCommerce product page pagination showing duplicates in all pages

I am getting the same results for each page using the WooCommerce pagination. What am I doing wrong? Maybe it lacks postdata reset somewhere? This is my code example:

Link to full code—>

$products = new WP_Query($product_args);
if ($products->have_posts()):
    while ($products->have_posts()):
        $products->the_post();
        wc_get_template_part("content", "product");
    endwhile;
    wp_reset_postdata($products);
endif;
 
echo paginate_links([
    "base" => str_replace(
        999999999,
        "%#%",
        esc_url(get_pagenum_link(999999999))
    ),
    "total" => $products->max_num_pages,
    "current" => max(1, get_query_var("paged")),
    "format" => "?paged=%#%",
    "show_all" => false,
    "type" => "list",
    "end_size" => 2,
    "mid_size" => 4,
    "prev_next" => true,
    "prev_text" => is_rtl() ? "→" : "←",
    "next_text" => is_rtl() ? "←" : "→",
    "add_args" => false,
    "add_fragment" => "",
]);

Thanks to @Outsource WordPress comment I was lead to a solution. I changed the part of my code like this and got it working. I replaced offset with paged:

$product_args = [
"post_type" => "product",
"post_status" => "publish",
"orderby" => "ID",
"suppress_filters" => false,
"order" => "ASC",
"paged" => max(1, get_query_var('paged')),
"posts_per_page" => "16",
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM