Make WordPress Core

Ticket #14477: 14477.4.diff

File 14477.4.diff, 2.0 KB (added by wonderboymusic, 10 years ago)
  • src/wp-includes/post.php

     
    42904290function get_page_children($page_id, $pages) {
    42914291        $page_list = array();
    42924292        foreach ( (array) $pages as $page ) {
    4293                 if ( $page->post_parent == $page_id ) {
     4293                if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) {
    42944294                        $page_list[] = $page;
    42954295                        if ( $children = get_page_children($page->ID, $pages) )
    42964296                                $page_list = array_merge($page_list, $children);
     
    46244624        // Update cache.
    46254625        update_post_cache( $pages );
    46264626
     4627        // Convert to WP_Post instances
     4628        $pages = array_map( 'get_post', $pages );
     4629
    46274630        if ( $child_of || $hierarchical ) {
    46284631                $pages = get_page_children($child_of, $pages);
    46294632        }
     
    46524655
    46534656        wp_cache_set( $cache_key, $page_structure, 'posts' );
    46544657
    4655         // Convert to WP_Post instances.
    4656         $pages = array_map( 'get_post', $pages );
    4657 
    46584658        /**
    46594659         * Filter the retrieved list of pages.
    46604660         *
  • tests/phpunit/tests/post/getPages.php

     
    268268                $exclude6 = get_pages( array( 'exclude_tree' => array( $post_id1, $post_id3 ) ) );
    269269                $this->assertCount( 2, $exclude6 );
    270270        }
     271
     272        function test_get_pages_interrupted_hierarchy() {
     273                $page1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     274                $page2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page1 ) );
     275                add_post_meta( $page2, 'color', 'red' );
     276                $page3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page2 ) );
     277                add_post_meta( $page3, 'color', 'blue' );
     278
     279                $pages = get_pages( array( 'child_of' => $page1, 'meta_key' => 'color', 'meta_value' => 'blue' ) );
     280                $this->assertEqualSets( array( $page3 ), wp_list_pluck( $pages, 'ID' ) );
     281        }
    271282}
     283 No newline at end of file