WP Page Navi. 404 error when using posts per page parameter

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=5paged=' . $paged);
?

?php if (have_posts()) : ?
?php while (have_posts()) : the_post(); ?
            lia 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.

Topic plugin-wp-pagenavi pagination 404-error Wordpress

Category Web


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!


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.