Reputation: 267
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:
$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" => "",
]);
Upvotes: 3
Views: 919
Reputation: 267
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",
];
Upvotes: 1