diff --git src/wp-includes/post.php src/wp-includes/post.php
index 96f0120..2caba86 100644
|
|
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) |
4284 | 4284 | function get_page_children( $page_id, $pages ) { |
4285 | 4285 | $page_list = array(); |
4286 | 4286 | foreach ( (array) $pages as $page ) { |
4287 | | if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) { |
| 4287 | if ( $page->post_parent == $page_id ) { |
4288 | 4288 | $page_list[] = $page; |
4289 | | if ( $children = get_page_children( $page->ID, $pages, false ) ) { |
| 4289 | if ( $children = get_page_children( $page->ID, $pages ) ) { |
4290 | 4290 | $page_list = array_merge( $page_list, $children ); |
4291 | 4291 | } |
4292 | 4292 | } |
4293 | 4293 | } |
4294 | 4294 | |
4295 | | // Ensure uniqueness. |
4296 | | $page_ids = array(); |
4297 | | $unique_page_list = array(); |
4298 | | foreach ( $page_list as $page_list_item ) { |
4299 | | if ( ! in_array( $page_list_item->ID, $page_ids ) ) { |
4300 | | $unique_page_list[] = $page_list_item; |
4301 | | $page_ids[] = $page_list_item->ID; |
4302 | | } |
4303 | | } |
4304 | | |
4305 | | return $unique_page_list; |
| 4295 | return $page_list; |
4306 | 4296 | } |
4307 | 4297 | |
4308 | 4298 | /** |
… |
… |
function get_pages( $args = array() ) { |
4630 | 4620 | // Update cache. |
4631 | 4621 | update_post_cache( $pages ); |
4632 | 4622 | |
4633 | | // Convert to WP_Post instances |
4634 | | $pages = array_map( 'get_post', $pages ); |
4635 | | |
4636 | 4623 | if ( $child_of || $hierarchical ) { |
4637 | 4624 | $pages = get_page_children($child_of, $pages); |
4638 | 4625 | } |
… |
… |
function get_pages( $args = array() ) { |
4661 | 4648 | |
4662 | 4649 | wp_cache_set( $cache_key, $page_structure, 'posts' ); |
4663 | 4650 | |
| 4651 | // Convert to WP_Post instances |
| 4652 | $pages = array_map( 'get_post', $pages ); |
| 4653 | |
4664 | 4654 | /** |
4665 | 4655 | * Filter the retrieved list of pages. |
4666 | 4656 | * |
diff --git tests/phpunit/tests/post/getPages.php tests/phpunit/tests/post/getPages.php
index 6a8d934..4f4f473 100644
|
|
class Tests_Post_getPages extends WP_UnitTestCase { |
270 | 270 | $exclude6 = get_pages( array( 'exclude_tree' => array( $post_id1, $post_id3 ) ) ); |
271 | 271 | $this->assertCount( 2, $exclude6 ); |
272 | 272 | } |
273 | | |
274 | | /** |
275 | | * @ticket 14477 |
276 | | */ |
277 | | function test_get_pages_interrupted_hierarchy() { |
278 | | $page1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); |
279 | | $page2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page1 ) ); |
280 | | add_post_meta( $page2, 'color', 'red' ); |
281 | | $page3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page2 ) ); |
282 | | add_post_meta( $page3, 'color', 'blue' ); |
283 | | |
284 | | $pages = get_pages( array( 'child_of' => $page1, 'meta_key' => 'color', 'meta_value' => 'blue' ) ); |
285 | | $this->assertEqualSets( array( $page3 ), wp_list_pluck( $pages, 'ID' ) ); |
286 | | } |
287 | 273 | } |