Ticket #14477: 14477.3.diff
File 14477.3.diff, 2.0 KB (added by , 11 years ago) |
---|
-
tests/phpunit/tests/post/getPages.php
128 128 $post_ids = get_children( array( 'fields' => 'ids', 'post_parent' => $post_id ) ); 129 129 $this->assertEqualSets( $child_ids, $post_ids ); 130 130 } 131 132 function test_get_pages_interrupted_hierarchy() { 133 $page1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); 134 $page2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page1 ) ); 135 add_post_meta( $page2, 'color', 'red' ); 136 $page3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page2 ) ); 137 add_post_meta( $page3, 'color', 'blue' ); 138 139 $pages = get_pages( array( 'child_of' => $page1, 'meta_key' => 'color', 'meta_value' => 'blue' ) ); 140 $this->assertEqualSets( array( $page3 ), wp_list_pluck( $pages, 'ID' ) ); 141 } 131 142 } 143 No newline at end of file -
src/wp-includes/post.php
3535 3535 function get_page_children($page_id, $pages) { 3536 3536 $page_list = array(); 3537 3537 foreach ( (array) $pages as $page ) { 3538 if ( $page->post_parent == $page_id ) {3538 if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) { 3539 3539 $page_list[] = $page; 3540 3540 if ( $children = get_page_children($page->ID, $pages) ) 3541 3541 $page_list = array_merge($page_list, $children); … … 3813 3813 // Update cache. 3814 3814 update_post_cache( $pages ); 3815 3815 3816 // Convert to WP_Post instances 3817 $pages = array_map( 'get_post', $pages ); 3818 3816 3819 if ( $child_of || $hierarchical ) 3817 3820 $pages = get_page_children($child_of, $pages); 3818 3821 … … 3836 3839 3837 3840 wp_cache_set( $cache_key, $page_structure, 'posts' ); 3838 3841 3839 // Convert to WP_Post instances3840 $pages = array_map( 'get_post', $pages );3841 3842 3842 $pages = apply_filters('get_pages', $pages, $r); 3843 3843 3844 3844 return $pages;