I have a custom query to display my custom post type. posts_per_page
set to ‘5’. In admin post per page set to ’10’ (settings => Reading => Blog pages show at most 10 posts)
My template lists 5 posts per page. If I have 15 posts it must be shown in 3 pages, but on third page I get 404 error. So my pagination uses the admin settings (10 posts per page). How can I fix it?
global $paged;
query_posts(array(
'post_type' => 'custom_post_type',
'posts_per_page' => 5,
'orderby' => 'title',
'order' => 'ASC',
'paged' => $paged
));
while (have_posts()) : the_post();
the_title();
endwhile;
next_posts_link('Next');
previous_posts_link('Prev');
Pagination is calculated before you get to the template file that runs
query_posts
. The proper way to alterposts_per_page
conditionally is to use thepre_get_posts
hook to modify the main query.