Ecommerce Shopify WordPress Discussion

custom query pagination worpress

I'm pretty new to wordpress. My custom query pagination not working properly, it arrives until page 17 than stops working (i have 21 pages of products). I have tried to change it with pre get posts function but it doesn't work as expected. what could be the issue and what i can try? <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $term = get_queried_object(); $args = array( 'post_type' => 'product', 'posts_per_page' => 12, 'paged' => $paged, ); if ($term instanceof WP_Term && 'product_cat' === $term->taxonomy) { $taxonomy_slug = $term->slug; // Custom query to get products from the current taxonomy. $args = array( 'post_type' => 'product', 'posts_per_page' => 12, 'paged' => $paged, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $taxonomy_slug, ), ), ); } $query = new WP_Query($args); if (strpos($_SERVER['REQUEST_URI'], 'category') !== false) { // Filter categories based on the visible products $object_ids = $query->posts ? wp_list_pluck($query->posts, 'ID') : array(); } else { // No filtering, include all products $object_ids = array(); } $product_categories = get_terms(array( 'taxonomy' => 'product_cat', 'hide_empty' => true, // Exclude empty categories 'object_ids' => $query->posts ? wp_list_pluck($query->posts, 'ID') : array(), )); ?> <div class="pagination"> <?php $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $query->max_num_pages ) ); ?> </div>
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.