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