Allow get_pages()
to accept an array
for the arg parent
. Adds unit tests, some will fail until the next commit.
Fixes #9470. git-svn-id: https://develop.svn.wordpress.org/trunk@25244 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0e79ec02a6
commit
0b28c0137d
@ -3735,8 +3735,13 @@ function get_pages($args = '') {
|
||||
|
||||
}
|
||||
|
||||
if ( $parent >= 0 )
|
||||
if ( is_array( $parent ) ) {
|
||||
$post_parent__in = implode( ',', array_map( 'absint', (array) $parent ) );
|
||||
if ( ! empty( $post_parent__in ) )
|
||||
$where .= " AND post_parent IN ($post_parent__in)";
|
||||
} elseif ( $parent >= 0 ) {
|
||||
$where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
|
||||
}
|
||||
|
||||
if ( 1 == count( $post_status ) ) {
|
||||
$where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $post_type, array_shift( $post_status ) );
|
||||
|
@ -823,4 +823,29 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
sort( $exc_result );
|
||||
$this->assertEquals( $inc, $exc_result );
|
||||
}
|
||||
|
||||
function test_get_pages_parent() {
|
||||
$page_id1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
|
||||
$page_id2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id1 ) );
|
||||
$page_id3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id2 ) );
|
||||
$page_id4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id1 ) );
|
||||
|
||||
$pages = get_pages( array( 'parent' => 0, 'hierarchical' => false ) );
|
||||
$this->assertEqualSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
|
||||
|
||||
$pages = get_pages( array( 'parent' => $page_id1, 'hierarchical' => false ) );
|
||||
$this->assertEqualSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
|
||||
|
||||
$pages = get_pages( array( 'parent' => array( $page_id1, $page_id2 ), 'hierarchical' => false ) );
|
||||
$this->assertEqualSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
|
||||
|
||||
$pages = get_pages( array( 'parent' => 0 ) );
|
||||
$this->assertEqualSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
|
||||
|
||||
$pages = get_pages( array( 'parent' => $page_id1 ) );
|
||||
$this->assertEqualSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
|
||||
|
||||
$pages = get_pages( array( 'parent' => array( $page_id1, $page_id2 ) ) );
|
||||
$this->assertEqualSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user