Opened 13 years ago
Closed 13 years ago
#19463 closed defect (bug) (wontfix)
Archive page should not return 404 when requested page is larger than max page
Reported by: | kayue | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | |
Component: | Query | Keywords: | needs-patch close |
Focuses: | Cc: |
Description
Right now Wordpress return 404 when requested page number is larger than max page, and this could be a problem when people changed posts_per_page on query_posts.
For example, assuming the default post per page is 10 (in Reading Settings), and there are 15 posts in archive page (total 2 pages).
In archive.php, if I change the post_per_page to 5, there will be totally 3 pages. With the current implementation, the third page will return 404 page not found, because with the default setting, this page shouldn't exist.
I suggest Wordpress should still load archive.php even requested page is larger than max page, and use have_posts() to determine what to display (similar to loop-home.php)
Related discussions in forum:
The correct solution here is to alter the Query BEFORE WordPress makes the query, This can be done via the pre_get_posts or the request filters, both allow you to alter the query vars which will be used for the page query.
In your example, The 3rd page of the archive IS a 404, as WordPress has already made the query, and come up with 0 posts. As a result, it's no longer an archive, as there are no posts to display in an archive. Using query_posts() within a template to change the post count is a bad thing, and something which should never be recommended - primarily for this reason, but also for performance reasons (It's effectively loading 2 pages for the single page)
This article has some decent code for changing searches posts_per_page: http://soulsizzle.com/wordpress/display-a-different-number-of-posts-in-wordpress-searches/
replace ->is_search with ->is_archive and/or other query-related alterations you'd like to make (ie. only category archives, or tag ID 345, etc) and WordPress will work "as expected"