[wp-trac] [WordPress Trac] #36889: WP_Query 'post_limits' filter conflicting with 'posts_per_page' parameter

WordPress Trac noreply at wordpress.org
Thu May 19 12:23:24 UTC 2016


#36889: WP_Query 'post_limits' filter conflicting with 'posts_per_page' parameter
--------------------------+----------------------
 Reporter:  romulodl      |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Query         |     Version:  4.5.2
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+----------------------
Changes (by dd32):

 * status:  new => closed
 * resolution:   => invalid
 * milestone:  Awaiting Review =>


Comment:

 Hey @romulodl and welcome to trac!

 Filters such as `post_limits` are sufficiently low-level that it's
 unrealistic to expect the resulting `WP_Query` to know about what has
 happened at the SQL level.

 As far as `WP_Query` knows, it's paginated to 5 posts per page, and it's
 been told there's 10 results. It can't really be expected to parse the SQL
 and figure out that it's changed, just the same as all the query variables
 don't update to reflect extra conditionals added through the
 `posts_where_paged` filter.

 It's entirely possible that the function hooked to the filter could use
 the instance passed as the 2nd parameter to the filter to manipulate the
 `WP_Query` instance to make it aware of the new parameters.

 But I'd suggest the for 99% of cases, including the example here, using
 `pre_get_posts` to alter the `posts_per_page` would be the much smarter
 move, leaving the SQL filters for literal last measure when needing to
 alter the underlying query.

 I'm marking this as invalid, as I don't think we need to write a SQL
 parser just yet :)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36889#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list