[wp-trac] [WordPress Trac] #21733: WP_Query::have_posts should work when "fields" is set

WordPress Trac wp-trac at lists.automattic.com
Wed Aug 29 18:49:14 UTC 2012


#21733: WP_Query::have_posts should work when "fields" is set
----------------------------+-----------------------------
 Reporter:  wonderboymusic  |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Query           |    Version:
 Severity:  normal          |   Keywords:  has-patch
----------------------------+-----------------------------
 If you set {{{fields}}} to {{{ids}}} or {{{id=>parent}}} in a
 {{{WP_Query}}} instance, {{{WP_Query::post_count}}} does not get set, so
 {{{WP_Query::have_posts()}}} returns {{{false}}}. It shouldn't.

 To test:

 {{{
 $q = new WP_Query( array( 'posts_per_page' => -1 ));
 var_dump( $q->have_posts() );

 $q = new WP_Query( array( 'posts_per_page' => -1, 'fields' => 'ids' ) );
 var_dump( $q->have_posts() );
 exit();
 }}}

 You get this for free just by setting {{{WP_Query::post_count}}} - patch
 attached

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


More information about the wp-trac mailing list