Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#21733 closed defect (bug) (duplicate)

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

Reported by: wonderboymusic's profile wonderboymusic Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch
Focuses: 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 12 years ago.

Download all attachments as: .zip

Change History (3)

#1 @wonderboymusic
12 years ago

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

dupe of #21147

#2 @SergeyBiryukov
12 years ago

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