Avoid resetting the 'hierarchical' argument in get_pages() when 'parent' is -1, the default.
Fixes a regression introduced in [25270]. Adds unit tests. props chrisbliss18. fixes #25750. git-svn-id: https://develop.svn.wordpress.org/trunk@25974 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4be9031dc3
commit
2cac0fde8a
@ -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
|
||||
|
@ -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' ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user