diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index ceaa1d96a8..8a0e36b68b 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4245,7 +4245,7 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { if ( '0' === $cached || 0 === $cached ) { return; } else { - return get_post( $cached ); + return get_post( $cached, $output ); } } diff --git a/tests/phpunit/tests/post/getPageByPath.php b/tests/phpunit/tests/post/getPageByPath.php index 01271bcaa2..2390903e2d 100644 --- a/tests/phpunit/tests/post/getPageByPath.php +++ b/tests/phpunit/tests/post/getPageByPath.php @@ -242,4 +242,30 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase { $num_queries++; $this->assertSame( $num_queries, $wpdb->num_queries ); } + + /** + * @ticket 37611 + */ + public function test_output_param_should_be_obeyed_for_cached_value() { + $page = self::factory()->post->create( array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) ); + + // Prime cache. + $found = get_page_by_path( 'foo' ); + $this->assertSame( $page, $found->ID ); + + $object = get_page_by_path( 'foo', OBJECT ); + $this->assertInternalType( 'object', $object ); + $this->assertSame( $page, $object->ID ); + + $array_n = get_page_by_path( 'foo', ARRAY_N ); + $this->assertInternalType( 'array', $array_n ); + $this->assertSame( $page, $array_n[0] ); + + $array_a = get_page_by_path( 'foo', ARRAY_A ); + $this->assertInternalType( 'array', $array_a ); + $this->assertSame( $page, $array_a['ID'] ); + } }