0

I'm trying to fix an error with pagination of WP page Navi plugin. After I've added posts_per_page parameter to the query I'm getting 404 error when clicking on link page3,4 etc (there are 10 records totally) and after page 8 (where there around 60 records totally). Without this parameter it works fine but I want to display various number of posts under categories.

Here is the code of one of the pages I'm trying to fix:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($query_string .'&posts_per_page=5&paged=' . $paged);
?>

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
            <li><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<?php _e('Sorry, no posts matched your criteria.'); ?>

<?php endif; ?>
</ul>
<?php if (function_exists('wp_pagenavi')){ wp_pagenavi(); } ?>

Any help is much appreciated.

2
  • Never use query_posts, it will cause problems like breaking pagination. Use WP_Query or get_posts instead.
    – Gabriel
    Jul 17, 2015 at 23:18
  • Actually, I've tried to use WP_Query instead of query_posts but problem is still there. Jul 19, 2015 at 11:50

2 Answers 2

1

Finally, I've found an answer. Not sure if it's specific in my case or it's a general WP issue but default value for posts per page set up in WP admin (General > Reading > Maximum number of posts per page) should be less than value for posts_per_page parameter for custom query. In my case, I've changed in WP options value to 3 and for other page changed this to 5 and all working fine now!

1
  • 2
    This is happening because you are running a custom query when you should not. This is in all probability on your home page or some kind of archive page like category.php. Jul 19, 2015 at 13:32
0

You may want to take a look at this related issue: WP-PageNavi gives me a 404 when using WP Query

Some users mentioning that the page name cannot be the same as the post type you are querying, and others that it may be a conflict with another plugin you are running.

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