Ticket #17374: 17374.patch
| File 17374.patch, 3.0 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/post.php
3593 3593 * @return array 3594 3594 */ 3595 3595 function get_page_children($page_id, $pages) { 3596 $page_list = array(); 3597 foreach ( (array) $pages as $page ) { 3598 if ( $page->post_parent == $page_id ) { 3599 $page_list[] = $page; 3600 if ( $children = get_page_children($page->ID, $pages) ) 3601 $page_list = array_merge($page_list, $children); 3596 // a mapping of page->ID to page 3597 $page_dictionary = array(); 3598 // the child filtered pages that will be returned 3599 $page_list = array(); 3600 3601 // create ID -> page map 3602 foreach( (array) $pages as $page ) { 3603 $page_dictionary[$page->ID] = $page; 3604 } 3605 3606 foreach ( (array) $pages as $page) { 3607 $child_page = $page; 3608 3609 // look for the parent of the page 3610 while ( $child_page->post_parent && $child_page->post_parent != $page_id && $child_page->post_parent != $child_page->ID) { 3611 if ( isset($page_dictionary[$child_page->post_parent]) ) { 3612 $child_page = $page_dictionary[$child_page->post_parent]; 3613 } else { 3614 break; 3615 } 3602 3616 } 3617 3618 // if the parent of the page is the parent we are looking for, 3619 // add it to the page list 3620 if ($child_page->post_parent == $page_id) { 3621 $page_list[]= $page; 3622 } 3603 3623 } 3624 3604 3625 return $page_list; 3605 3626 } 3606 3627 -
tests/phpunit/tests/post/getPages.php
211 211 212 212 $this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) ); 213 213 } 214 215 /** 216 * @ticket 17374 217 */ 218 function test_get_pages_sorted_and_child_of() { 219 global $wpdb; 220 221 $create_time = '2014-02-21 22:06:23'; 222 223 $top_level_page = $this->factory->post->create( array( 'post_type' => 'page' ) ); 224 225 $sub_page_1 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $top_level_page ) ); 226 $sub_page_2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $top_level_page ) ); 227 228 $sub_sub_page_1 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $sub_page_1 ) ); 229 230 $this->factory->post->update_object($top_level_page, array( 'post_date' => '2014-02-21 22:06:23' )); 231 $this->factory->post->update_object($sub_page_1, array( 'post_date' => '2014-02-21 22:06:24' )); 232 $this->factory->post->update_object($sub_page_2, array( 'post_date' => '2014-02-21 22:06:25')); 233 $this->factory->post->update_object($sub_sub_page_1, array( 'post_date' => '2014-02-21 22:06:26' )); 234 235 $pages = get_pages(array( 'child_of' => $top_level_page, 'sort_column' => 'post_date', 'sort_order' => 'DESC')); 236 237 for ($i = 1; $i < count($pages); $i++) { 238 echo($pages[$i - 1]->post_date); 239 $this->assertGreaterThan($pages[$i]->post_date, $pages[$i - 1]->post_date); 240 } 241 } 214 242 } 243 No newline at end of file