diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 39d71a37c8..8770b0dc4f 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -3706,7 +3706,7 @@ function get_pages( $args = array() ) { if ( !in_array( $post_type, $hierarchical_post_types ) ) return $pages; - if ( $parent && ! $child_of ) + if ( $parent > 0 && ! $child_of ) $hierarchical = false; // Make sure we have a valid post status diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 6e6e4094d6..f4da909c46 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -829,4 +829,34 @@ class Tests_Post extends WP_UnitTestCase { $counts->publish = 7; return $counts; } + + /** + * @ticket 25750 + */ + function test_get_pages_hierarchical_and_no_parent() { + global $wpdb; + $page_1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); + $page_2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); + $page_3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); + $page_4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_2 ) ); + + $pages = get_pages(); // Defaults: hierarchical = true, parent = -1 + $pages_default_args = get_pages( array( 'hierarchical' => true, 'parent' => -1 ) ); + // Confirm the defaults. + $this->assertEquals( $pages, $pages_default_args ); + + /* + * Here's the tree we are testing: + * + * page 1 + * - page 2 + * -- page 4 + * - page 3 + * + * If hierarchical => true works, the order will be 1,2,4,3. + * If it doesn't, they will be in the creation order, 1,2,3,4. + */ + + $this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) ); + } }