My pagination isn't working for my archive.php, which I'm using as a template for my blog post categories links.

<div class="row">
            <?php $the_query = new WP_Query( array(
                'paged' => get_query_var('paged') ? get_query_var('paged') : 1) 
            ); ?>

            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
                <div class="col-lg-4 col-md-4 col-sm-12 blog-content text-styles">
                    <a class="blog-post-area" href="<?php the_permalink() ?>">
                        <?php if ( has_post_thumbnail() ) { 
                            the_post_thumbnail('main-news-thumbnail-uncropped', array('class' => 'img-fluid post-image'));
                        } ?> 
                        <h3 class="post-title"><?php the_title() ?></h3>
                        <?php the_excerpt() ?>
                        <a class="blog-post" href="<?php the_permalink() ?>">Read More</a>
                    </a><!--End Link-->
                </div><!--End Columns-->
            <?php endwhile; ?>
        </div><!--End Row-->

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12">
                <div class="pagination">
                        $big = 999999999; // need an unlikely integer?>
                        <?php echo paginate_links( array(
                            'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                            'format' => '?paged=%#%',
                            'current' => max( 1, get_query_var('paged') ),
                            'total' => $the_query->max_num_pages
                        ) );
                    <?php wp_reset_postdata();?>
                </div><!--End Pagination-->
            </div><!--End Columns--->
        </div><!--End Row-->

Any ideas? I can't figure it out!

  • What do you mean by "is not working"? Pager not being displayed? Clicking next does what? Have you tried other answers from here or maybe stackoverflow.com/questions/39471735/…?
    – leymannx
    Jun 7, 2019 at 11:02
  • archive.php should not be using a custom query. Why are you using $the_query = new WP_Query? For the main templates you should just be using have_posts() and the_post() without $the_query->. Jun 7, 2019 at 14:03

1 Answer 1


You're calling wp_reset_postdata() twice. Once is before the call to paginate_links().

  • Hi Mike, i've removed that now - also updated code above. But I'm still getting the error - i'm just being taken to my 404 Error page. Could it be a pagination error?
    – M.T
    Jun 6, 2019 at 14:47
  • I think you're running into a conflict between the query that's already being run and this new query. The response you're getting from WordPress (404) is being dictated by the default query, not your new query. Your simultaneously paginating both your new query and the default query at the same time. Does that make sense? Jun 6, 2019 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.