Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#21733 closed defect (bug) (duplicate)

WP_Query::have_posts should work when "fields" is set

Reported by: wonderboymusic Owned by:
Priority: normal Milestone:
Component: Query Version:
Severity: normal Keywords: has-patch
Cc:

Description

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

Attachments (1)

fields-count.diff (695 bytes) - added by wonderboymusic 9 months ago.

Download all attachments as: .zip

Change History (3)

  • Resolution set to duplicate
  • Status changed from new to closed

dupe of #21147

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.