WordPress.org

Make WordPress Core

Ticket #9153: get_pages_exclude_tree_multi.patch

File get_pages_exclude_tree_multi.patch, 1.3 KB (added by roothorick, 23 months ago)

I think this is the optimization Denis is talking about.

  • wp-includes/post.php

    diff -r -u wordpress-3.2.1/wp-includes/post.php wordpress/wp-includes/post.php
    old new  
    33313331                'sort_column' => 'post_title', 'hierarchical' => 1, 
    33323332                'exclude' => array(), 'include' => array(), 
    33333333                'meta_key' => '', 'meta_value' => '', 
    3334                 'authors' => '', 'parent' => -1, 'exclude_tree' => '', 
     3334                'authors' => '', 'parent' => -1, 'exclude_tree' => array(), 
    33353335                'number' => '', 'offset' => 0, 
    33363336                'post_type' => 'page', 'post_status' => 'publish', 
    33373337        ); 
     
    35153515                $pages = & get_page_children($child_of, $pages); 
    35163516 
    35173517        if ( !empty($exclude_tree) ) { 
    3518                 $exclude = (int) $exclude_tree; 
    3519                 $children = get_page_children($exclude, $pages); 
    3520                 $excludes = array(); 
    3521                 foreach ( $children as $child ) 
    3522                         $excludes[] = $child->ID; 
    3523                 $excludes[] = $exclude; 
     3518                $exclude = preg_split('/[\s,]+/',$exclude_tree); 
     3519                foreach( $exclude as $id ) // Remember: works on a COPY 
     3520                { 
     3521                        $children = get_page_children($id, $pages);              
     3522                        foreach ( $children as $child ) 
     3523                                $exclude[] = $child->ID; 
     3524                } 
    35243525                $num_pages = count($pages); 
    35253526                for ( $i = 0; $i < $num_pages; $i++ ) { 
    3526                         if ( in_array($pages[$i]->ID, $excludes) ) 
     3527                        if ( in_array($pages[$i]->ID, $exclude) ) 
    35273528                                unset($pages[$i]); 
    35283529                } 
    35293530        }