I’m running into an issue where there are duplicate posts appearing in my paginated results. I suspect the issue is to do with my use of paginate_links(), but if anyone can see something obvious in my code, please let me know as I’m stuck.

Examples

  • Searching for term ‘magical’ shows duplicate posts in the paginated results.
  • The main loop is also showing duplicate posts towards the end of the paginated results (it’s a bit harder to see as there are lots of posts).

Code

// CHECK IF PAGINATION IS PRESENT
function osu_pagination_exists() {
    global $wp_query;
    return ($wp_query->max_num_pages > 1);
}

if(osu_pagination_exists()) : ?>
    <nav class="pagination clearfix">
        <?php // Numbered pagination
        global $wp_query;
        $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' => $wp_query->max_num_pages
        ) ); ?>
    </nav>
<?php endif; ?>

Read more here: Duplicate posts in paginated results


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: