1

I am working with a blog page that uses the following query:

<?php
    $paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
    query_posts("category_name=blog&posts_per_page=2&paged=".$paged);
?>

and my pagination looks like:

<?php
    $next = get_next_posts_link("Next >>");
    $prev = get_previous_posts_link("<< Prev");
    if ($prev || $next) { ?>
        <div id='pagi'>
    <?php } ?>
    <?php if ($next) { ?>
        <div class="right button">
            <?php echo $next; ?>
        </div>
    <?php } ?>
    <?php if ($prev) { ?>
        <div class="left button">
            <?php echo $prev; ?>
        </div>
    <?php } ?>
    <?php if ($prev || $next) { ?>
        <div class="clear">
            <!-- -->
        </div>
    <?php } ?>
    <?php if ($prev || $next) { ?>
        </div>
    <?php } 
?>

The pagination is working to a certain extent...I see the previous and next links and can click next until I get to page 3, instead of arriving at page 3 I get a 404, which is weird because I know there is more content WordPress just doesn't display it for some reason. Anyone know what could be causing this issue, the weird thing is I am using the exact code on another website without error :-( The permlinks are set to the default and I am not using a custom post type.

Thanks,
Josh

1 Answer 1

2

Ok,

Now this is particularly very odd...I found this forum post: http://wordpress.org/support/topic/error-404-on-pagination-when-changing-posts_per_page-on-query_posts

Which basically says that if you are restricting the number of posts to a number less than 10 (which is the WordPress default), sometimes it can break pagination. To fix this issue, all you have to do is set the default number to be less than 10, and that'll fix the pagination. That sounded odd to me, but I set my default number of posts per page to be 1 and presto, my pagination was fixed!

This fixes my issue, but I have no idea why, has anyone else run across this issue or know why WordPress breaks the pagination in this situation?

EDIT: After taking a look around, it seems as though your number of posts has to be larger than the WordPress default. For example, on my test blog I have 8 posts, so if I change the limit to 9 the pagination will still be broken...but if I change it to one, it works just fine, because I definitely have more than one post - this happens regardless of how may posts_per_page I set on my query. So odd...anyone know why this happens?

Thanks,
Josh

1
  • Indeed, when matching the posts per page in Reading under settings to the custom number of posts mentioned in the array it resolves it. Thanks. Feb 1, 2015 at 15:19

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.