[wp-trac] [WordPress Trac] #19728: WP_Query should constrict 'paged' to be within bounds of found_posts

WordPress Trac wp-trac at lists.automattic.com
Tue Jan 3 20:16:46 UTC 2012


#19728: WP_Query should constrict 'paged' to be within bounds of found_posts
-------------------------+-----------------------------
 Reporter:  Master Jake  |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Query        |    Version:
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 I apologize in advanced if this has been reported before. My Trac search
 did not find anything pressingly relevant.

 WP_Query allows the user to pass in a discrete value to use for the
 'paged' parameter; however, often times this value will be dynamic rather
 than static (as in the programmer will have paged be the value of $_GET[
 'paged' ] or something similar).

 The problem is, if you enter an absurdly large or small value for the
 paged parameter and it's out of bounds, it will just throw a 404 (or
 otherwise show that there are no posts matching the parameters). I propose
 that WP_Query automatically changes the paged value to be within the
 bounds of the returned number of pages.

 For example, constrict paged to the following rules:
 1 <= $paged <= $wp_query->max_num_pages (where $wp_query is whatever
 custom query is being used). If the user types in a page larger than the
 max, it uses the max instead. Conversely, if they type a page less than 1,
 it uses 1.

 The only potential problem I see with this is if a user actually (for
 whatever reason) wanted a 404 to display when an invalid page was
 visisted. In this case, perhaps we can introduce a new option to WP_Query
 such as 'limit_to_bounds' => true?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19728>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list