Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#27252 closed defect (bug) (fixed)

WP_Query's "fields" => "ids" should return an array of integers

Reported by: danielbachhuber's profile danielbachhuber Owned by: wonderboymusic's profile wonderboymusic
Milestone: 3.9 Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch dev-feedback
Focuses: Cc:

Description

When using WP_Query's "fields" => "ids" (or "fields" => "id=>parent"), the returned values should be an array of integers, not array of integers represented by strings.

The current, latter behavior causes a subsequent WP_Query with post__in to fail because it's being passed an array of strings.

Attachments (1)

27252.1.diff (3.4 KB) - added by danielbachhuber 10 years ago.
Cast returned post IDs as integers

Download all attachments as: .zip

Change History (6)

@danielbachhuber
10 years ago

Cast returned post IDs as integers

This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.


10 years ago

#2 @nacin
10 years ago

I'm all for this but post__in appears to accept an array of numeric strings fine:

$post__in = implode(',', array_map( 'absint', $q['post__in'] ));

#3 @wonderboymusic
10 years ago

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

In 27686:

When using WP_Query's "fields" => "ids" (or "fields" => "id=>parent"), the returned values should be an array of integers, not array of integers represented by strings.

Adds unit tests. All other unit tests pass.

Props danielbachhuber.
Fixes #27252.

#5 @SergeyBiryukov
9 years ago

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.