Ecommerce Shopify WordPress Discussion

WordPress WP_Query with offset generating an extra page in the pagination giving 404 error

I noticed the pagination is generating an extra page which gives a 404 error. How can I fix this? I have Settings > Reading set to 10 posts too. Something in my code below is returning the wrong number of total posts but I can't figure out how. PS: The offset is necessary. <?php get_header(); ?> <div class="container"> <div class="row"> <div class="col-md-12"> <?php $current_page = get_query_var('paged'); $current_page = max( 1, $current_page ); $per_page = 10; $offset_start = 4; $offset = ( $current_page - 1 ) * $per_page + $offset_start; $post_list = new WP_Query(array( /*'cat' => -15,*/ 'category' => $category_name, 'posts_per_page' => $per_page, 'paged' => $current_page, 'offset' => $offset, // Starts with the second most recent post. 'orderby' => 'date', // Makes sure the posts are sorted by date. 'order' => 'DESC', // And that the most recent ones come first. )); if ( $post_list->have_posts() ): while ( $post_list->have_posts() ): $post_list->the_post(); ?> <a href="<?php the_permalink(); ?>"> <span class="category"> <?php $category = get_the_category(); echo $category[0]->cat_name; ?> </span> <h2 class="card__title"><?php the_title(); ?></h2> </a> <?php endwhile; ?> <div class="pagination"> <?php echo paginate_links( array( 'total' => $post_list->max_num_pages, 'current' => $current_page, 'type' => 'plain', 'prev_text' => '«', 'next_text' => '»' ) ); ?> </div> <?php endif; wp_reset_postdata(); ?> </div> </div> </div> <?php get_footer(); ?>
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.