From 744a4a80a4876033c5f1b5a657b5174d282fe177 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 29 Aug 2013 15:07:59 +0000 Subject: [PATCH] Respect the `fields` arg when passed to `get_children()`. Fixes #22208. git-svn-id: https://develop.svn.wordpress.org/trunk@25160 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 5 ++++- tests/tests/post/getPages.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 55a09aefa9..c306d67baf 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -311,9 +311,12 @@ function get_children($args = '', $output = OBJECT) { $children = get_posts( $r ); - if ( !$children ) + if ( ! $children ) return $kids; + if ( ! empty( $r['fields'] ) ) + return $children; + update_post_cache($children); foreach ( $children as $key => $child ) diff --git a/tests/tests/post/getPages.php b/tests/tests/post/getPages.php index 7d7c5cea07..8b660252e1 100644 --- a/tests/tests/post/getPages.php +++ b/tests/tests/post/getPages.php @@ -117,4 +117,15 @@ class Tests_Post_getPages extends WP_UnitTestCase { $this->assertEquals( 5, count( $matches[0] ) ); } + + /** + * @ticket 22208 + */ + function test_get_chidren_fields_ids() { + $post_id = $this->factory->post->create(); + $child_ids = $this->factory->post->create_many( 5, array( 'post_parent' => $post_id ) ); + + $post_ids = get_children( array( 'fields' => 'ids', 'post_parent' => $post_id ) ); + $this->assertEqualSets( $child_ids, $post_ids ); + } } \ No newline at end of file