[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 11:58:22 UTC 2016


#36889: WP_Query 'post_limits' filter conflicting with 'posts_per_page' parameter
--------------------------+-----------------------------
 Reporter:  romulodl      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.5.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 If I hook in 'post_limits' or 'post_limits_request' to set a different
 limit and then query using 'posts_per_page'. the max_num_pages variables
 will follow the 'posts_per_page' param and not the 'post_limits' filter.

 {{{#!php
 <?php
     // supposing I have 10 published posts in the DB
     add_filter('post_limits', function($limit) {
         return 'LIMIT 0, 1';
     });

     $query = new WP_Query(array('posts_per_page' => 5));

     var_dump($query->max_num_pages);
     //=> It will be 2, should not be 10 because I am forcing LIMIT 0, 1?
 }}}

 My question is what it should be the correct behaviour? Obey the
 'post_limits' filter? Obey the 'posts_per_page' parameter?

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


More information about the wp-trac mailing list