Trying to get pagination working on WP_Query() post grid

If you’re set to a static front page, why would there be pagination?

The proper way to have a paginated grid of posts as your front page is to set the homepage to “Your latest posts”. You would then develop your front-page.php, home.php or index.php template to display posts as a grid (use the Template Hierarchy to determine which file you need).

In that template you don’t need to use WP_Query or $paged or anything like that. Only the main loop:

<h2>Recent Posts</h2>

<div class="grid row posts">
    <?php while ( have_posts() ) : the_post(); ?>
        <div class="col">
            <!-- Post markup goes here. -->
        </div>
    <?php endwhile; ?>
</div>

<div class="pagination">
    <?php 
    echo paginate_links( array(
        'end_size'     => 2,
        'mid_size'     => 1,
        'prev_text'    => sprintf( '<i></i> %1$s', __( 'Newer Posts', 'text-domain' ) ),
        'next_text'    => sprintf( '%1$s <i></i>', __( 'Older Posts', 'text-domain' ) ),
    ) );
    ?>
</div>

Note the other changes I made:

  • The pagination links should be outside the while loop.
  • I’ve removed arguments paginate_links() because they were either unnecessary due to the proper loop structure, or because they were just set to the defaults.

If you’ll humour me in the comments, this misuse of WP_Query and pagination is by far the most common mistake I see on this site, so I’m just curious where you got the idea that you needed to do a new WP_Query, because it should never be necessary for the main list of posts in any of the standard templates, but I see it done almost every day. Is there a tutorial out there spreading this, or something in the official docs that’s implying this?