Pagination gives extra page with no results

I’m trying to implement pagination on a category page. The pagination is working, but now for some reason the pagination plugin I’m using is noting one extra page of results, when that page is actually empty.

I’m pretty sure it doesn’t have anything to do with the pagination plugin because I’ve seen reports of people having the same problem with next_posts_link and previous_posts_link.

Read More

Anybody have any idea how this could happen?

Loop:

<?php       
global $myOffset;
$myOffset = 11;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('offset='.$myOffset.'&cat=6&posts_per_page=12'.'&paged='.$paged);
?>

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

STUFF

<?php endwhile; ?>

<?php if(function_exists('wp_paginate')) {
   // get yo paginate on
   wp_paginate();
} ?>

Edit:
I am also using this functions.php plugin to enable the offset parameter in a custom wp_query:

function my_post_limit($limit) {
    global $paged, $myOffset;
    if (empty($paged)) {
            $paged = 1;
    }
    $postperpage = intval(get_option('posts_per_page'));
    $pgstrt = ((intval($paged) -1) * $postperpage) + $myOffset . ', ';
    $limit = 'LIMIT '.$pgstrt.$postperpage;
    return $limit;
} //end function my_post_limit

Related posts

Leave a Reply

2 comments

  1. I am not sure, but I have a guess that it is because you are using pagination and offset at the same time. Pagination might be calculated for whole set, but you are reducing set size with offset so number of pages becomes overestimated.

  2. You could try to use the more native get_adjacent_posts() function to see if the problem is the next_posts_link() function. For additional information i wrote an educational plugin that’s well documented/commented to giude you through the process.