[wp-trac] [WordPress Trac] #19463: Archive page should not return 404 when requested page is larger than max page

WordPress Trac wp-trac at lists.automattic.com
Wed Dec 7 04:52:40 UTC 2011


#19463: Archive page should not return 404 when requested page is larger than max
page
-------------------------------+------------------------------
 Reporter:  kayue              |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Rewrite Rules      |     Version:
 Severity:  major              |  Resolution:
 Keywords:  needs-patch close  |
-------------------------------+------------------------------
Changes (by dd32):

 * keywords:  needs-patch => needs-patch close


Comment:

 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/
 {{{
 function change_wp_search_size($query) {
         if ( $query->is_search ) // Make sure it is a search page
                 $query->query_vars['posts_per_page'] = 10; // Change 10 to
 the number of posts you would like to show

         return $query; // Return our modified query variables
 }
 add_filter('pre_get_posts', 'change_wp_search_size'); // Hook our custom
 function onto the request filter
 }}}

 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"

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19463#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list