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. git-svn-id: https://develop.svn.wordpress.org/trunk@27686 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
651b4a5f5b
commit
710f11f2df
@ -2268,7 +2268,7 @@ class WP_Query {
|
|||||||
// This overrides posts_per_page.
|
// This overrides posts_per_page.
|
||||||
if ( ! empty( $q['posts_per_rss'] ) ) {
|
if ( ! empty( $q['posts_per_rss'] ) ) {
|
||||||
$q['posts_per_page'] = $q['posts_per_rss'];
|
$q['posts_per_page'] = $q['posts_per_rss'];
|
||||||
} else {
|
} else {
|
||||||
$q['posts_per_page'] = get_option( 'posts_per_rss' );
|
$q['posts_per_page'] = get_option( 'posts_per_rss' );
|
||||||
}
|
}
|
||||||
$q['nopaging'] = false;
|
$q['nopaging'] = false;
|
||||||
@ -3205,7 +3205,7 @@ class WP_Query {
|
|||||||
$this->post_count = count( $this->posts );
|
$this->post_count = count( $this->posts );
|
||||||
$this->set_found_posts( $q, $limits );
|
$this->set_found_posts( $q, $limits );
|
||||||
|
|
||||||
return $this->posts;
|
return array_map( 'intval', $this->posts );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'id=>parent' == $q['fields'] ) {
|
if ( 'id=>parent' == $q['fields'] ) {
|
||||||
@ -3214,9 +3214,9 @@ class WP_Query {
|
|||||||
$this->set_found_posts( $q, $limits );
|
$this->set_found_posts( $q, $limits );
|
||||||
|
|
||||||
$r = array();
|
$r = array();
|
||||||
foreach ( $this->posts as $post )
|
foreach ( $this->posts as $post ) {
|
||||||
$r[ $post->ID ] = $post->post_parent;
|
$r[ (int) $post->ID ] = (int) $post->post_parent;
|
||||||
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ class Tests_Query_Results extends WP_UnitTestCase {
|
|||||||
$this->parent_one = $this->factory->post->create( array( 'post_title' => 'parent-one', 'post_date' => '2007-01-01 00:00:00' ) );
|
$this->parent_one = $this->factory->post->create( array( 'post_title' => 'parent-one', 'post_date' => '2007-01-01 00:00:00' ) );
|
||||||
$this->parent_two = $this->factory->post->create( array( 'post_title' => 'parent-two', 'post_date' => '2007-01-01 00:00:00' ) );
|
$this->parent_two = $this->factory->post->create( array( 'post_title' => 'parent-two', 'post_date' => '2007-01-01 00:00:00' ) );
|
||||||
$this->parent_three = $this->factory->post->create( array( 'post_title' => 'parent-three', 'post_date' => '2007-01-01 00:00:00' ) );
|
$this->parent_three = $this->factory->post->create( array( 'post_title' => 'parent-three', 'post_date' => '2007-01-01 00:00:00' ) );
|
||||||
$this->factory->post->create( array( 'post_title' => 'child-one', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:01' ) );
|
$this->child_one = $this->factory->post->create( array( 'post_title' => 'child-one', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:01' ) );
|
||||||
$this->factory->post->create( array( 'post_title' => 'child-two', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:02' ) );
|
$this->child_two = $this->factory->post->create( array( 'post_title' => 'child-two', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:02' ) );
|
||||||
$this->factory->post->create( array( 'post_title' => 'child-three', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:03' ) );
|
$this->child_three = $this->factory->post->create( array( 'post_title' => 'child-three', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:03' ) );
|
||||||
$this->factory->post->create( array( 'post_title' => 'child-four', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:04' ) );
|
$this->child_four = $this->factory->post->create( array( 'post_title' => 'child-four', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:04' ) );
|
||||||
|
|
||||||
unset( $this->q );
|
unset( $this->q );
|
||||||
$this->q = new WP_Query();
|
$this->q = new WP_Query();
|
||||||
@ -370,6 +370,38 @@ class Tests_Query_Results extends WP_UnitTestCase {
|
|||||||
), wp_list_pluck( $posts, 'post_title' ) );
|
), wp_list_pluck( $posts, 'post_title' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 27252
|
||||||
|
*/
|
||||||
|
function test_query_fields_integers() {
|
||||||
|
|
||||||
|
$parents = array(
|
||||||
|
(int) $this->parent_one,
|
||||||
|
(int) $this->parent_two
|
||||||
|
);
|
||||||
|
$posts1 = $this->q->query( array(
|
||||||
|
'post__in' => $parents,
|
||||||
|
'fields' => 'ids',
|
||||||
|
'orderby' => 'post__in',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertSame( $parents, $posts1 );
|
||||||
|
|
||||||
|
$children = array(
|
||||||
|
(int) $this->child_one => (int) $this->parent_one,
|
||||||
|
(int) $this->child_two => (int) $this->parent_one
|
||||||
|
);
|
||||||
|
|
||||||
|
$posts2 = $this->q->query( array(
|
||||||
|
'post__in' => array_keys( $children ),
|
||||||
|
'fields' => 'id=>parent',
|
||||||
|
'orderby' => 'post__in',
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertSame( $children, $posts2 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function test_exlude_from_search_empty() {
|
function test_exlude_from_search_empty() {
|
||||||
global $wp_post_types;
|
global $wp_post_types;
|
||||||
foreach ( array_keys( $wp_post_types ) as $slug )
|
foreach ( array_keys( $wp_post_types ) as $slug )
|
||||||
|
Loading…
Reference in New Issue
Block a user