From 7c97e59ed65431a00fe641e09efa80c6e6da4b54 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 3 Feb 2015 02:29:25 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@31324 git-svn-id: http://core.svn.wordpress.org/trunk@31305 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 9 +++++++-- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 3c1b0c2bdb..ddb655370a 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -3421,10 +3421,11 @@ class WP_Query { if ( 'ids' == $q['fields'] ) { $this->posts = $wpdb->get_col( $this->request ); + $this->posts = array_map( 'intval', $this->posts ); $this->post_count = count( $this->posts ); $this->set_found_posts( $q, $limits ); - return array_map( 'intval', $this->posts ); + return $this->posts; } if ( 'id=>parent' == $q['fields'] ) { @@ -3433,9 +3434,13 @@ class WP_Query { $this->set_found_posts( $q, $limits ); $r = array(); - foreach ( $this->posts as $post ) { + foreach ( $this->posts as $key => $post ) { + $this->posts[ $key ]->ID = (int) $post->ID; + $this->posts[ $key ]->post_parent = (int) $post->post_parent; + $r[ (int) $post->ID ] = (int) $post->post_parent; } + return $r; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 903c0f8a17..31ccb64c29 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31323'; +$wp_version = '4.2-alpha-31324'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.