Make WordPress Core

Ticket #14477: 14477.2.diff

File 14477.2.diff, 2.1 KB (added by wonderboymusic, 11 years ago)
  • tests/tests/post/getPages.php

     
    117117
    118118                $this->assertEquals( 5, count( $matches[0] ) );
    119119        }
     120
     121        /**
     122         * @ticket 14477
     123         */
     124        function test_get_pages_interrupted_hierarchy() {
     125                $page1 = $this->factory->post->create( array( 'post_type' => 'page' ) );
     126                $page2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page1 ) );
     127                add_post_meta( $page2, 'color', 'red' );
     128                $page3 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page2 ) );
     129                add_post_meta( $page3, 'color', 'blue' );
     130
     131                $pages = get_pages( array( 'child_of' => $page1, 'meta_key' => 'color', 'meta_value' => 'blue' ) );
     132                $this->assertEqualSets( array( $page3 ), wp_list_pluck( $pages, 'ID' ) );
     133        }
    120134}
     135 No newline at end of file
  • src/wp-includes/post.php

    Property changes on: tests/data
    ___________________________________________________________________
    Added: svn:ignore
       + .trac-ticket-cache.unit-tests.trac.wordpress.org
    
    
     
    35093509function get_page_children($page_id, $pages) {
    35103510        $page_list = array();
    35113511        foreach ( (array) $pages as $page ) {
    3512                 if ( $page->post_parent == $page_id ) {
     3512                if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) {
    35133513                        $page_list[] = $page;
    35143514                        if ( $children = get_page_children($page->ID, $pages) )
    35153515                                $page_list = array_merge($page_list, $children);
     
    37953795        // Update cache.
    37963796        update_post_cache( $pages );
    37973797
     3798        // Convert to WP_Post instances
     3799        $pages = array_map( 'get_post', $pages );
     3800
    37983801        if ( $child_of || $hierarchical )
    37993802                $pages = get_page_children($child_of, $pages);
    38003803
     
    38183821
    38193822        wp_cache_set( $cache_key, $page_structure, 'posts' );
    38203823
    3821         // Convert to WP_Post instances
    3822         $pages = array_map( 'get_post', $pages );
    3823 
    38243824        $pages = apply_filters('get_pages', $pages, $r);
    38253825
    38263826        return $pages;