From 5a018010abad248564ab1ea1ef91be072b0cbd07 Mon Sep 17 00:00:00 2001 From: Juzar Bharmal <53657281+Juzar10@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:18:36 +0530 Subject: [PATCH] test: add test case for the id=>parent WP_Query the_posts object --- tests/phpunit/tests/query.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index 37dd51a06392a..e3db591b7237e 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -745,6 +745,28 @@ static function () { $this->assertSame( '/* posts_join_paged */', $posts_clauses['join'] ); } + /** + * @ticket 56992 + */ + public function test_the_loop_when_querying_post_parents_only() { + $parent = self::factory()->post->create( array( 'post_type' => 'page' ) ); + $child = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $parent ) ); + + $query = new WP_Query( + array( + 'fields' => 'id=>parent', + 'post_type' => 'page', + 'page_id' => $child, + ) + ); + + $query->the_post(); + $global_post = get_post( null, ARRAY_A ); + $specific_post = get_post( $child, ARRAY_A ); + + $this->assertEqualSetsWithIndex( $global_post, $specific_post ); + } + /** * Tests that the `posts_clauses_request` filter receives an array of clauses * with the other `posts_*_request` filters applied, e.g. `posts_join_request`.