Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#31194 closed defect (bug) (fixed)

WP_Query's 'fields' => 'ids' still returns an array of strings

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.2 Priority: normal
Severity: normal Version: 3.9
Component: Query Keywords: has-patch commit
Focuses: Cc:

Description

#27252 attempted to make WP_Query's 'fields' => 'ids' or 'fields' => 'id=>parent' return an array of integers instead of numeric strings. However, the fix was incomplete.

This returns an array of integers:

$query = new WP_Query();
$posts = $query->query( array( 'fields' => 'ids' ) );
var_dump( $posts );

array(1) {
  [0]=>
  int(131)
}

This still returns an array of strings:

$query = new WP_Query( array( 'fields' => 'ids' ) );
var_dump( $query->posts );

array(1) {
  [0]=>
  string(3) "131"
}

The unit test added in [27686] didn't catch this, because it only tested $q->query() and not $q->posts.

Attachments (1)

31194.patch (1.7 KB) - added by SergeyBiryukov 9 years ago.

Download all attachments as: .zip

Change History (5)

#1 @DrewAPicture
9 years ago

  • Keywords commit added

OK (1 test, 7 assertions)

Patch fixes it for me, and tests pass.

#3 @danielbachhuber
9 years ago

Thanks for the catch, @SergeyBiryukov

#4 @SergeyBiryukov
9 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 31324:

When using WP_Query's 'fields' => 'ids' (or 'fields' => 'id=>parent'), make sure the returned result is always an array of integers.

fixes #31194. see #27252.

Note: See TracTickets for help on using tickets.