Changeset 27767
- Timestamp:
- 03/27/2014 01:17:41 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r27726 r27767 3743 3743 'exclude' => array(), 'include' => array(), 3744 3744 'meta_key' => '', 'meta_value' => '', 3745 'authors' => '', 'parent' => -1, 'exclude_tree' => '',3745 'authors' => '', 'parent' => -1, 'exclude_tree' => array(), 3746 3746 'number' => '', 'offset' => 0, 3747 3747 'post_type' => 'page', 'post_status' => 'publish', … … 3925 3925 $pages = get_page_children($child_of, $pages); 3926 3926 3927 if ( !empty($exclude_tree) ) { 3928 $exclude = (int) $exclude_tree; 3929 $children = get_page_children($exclude, $pages); 3930 $excludes = array(); 3931 foreach ( $children as $child ) 3932 $excludes[] = $child->ID; 3933 $excludes[] = $exclude; 3934 $num_pages = count($pages); 3927 if ( ! empty( $exclude_tree ) ) { 3928 $exclude = wp_parse_id_list( $exclude_tree ); 3929 foreach( $exclude as $id ) { 3930 $children = get_page_children( $id, $pages ); 3931 foreach ( $children as $child ) { 3932 $exclude[] = $child->ID; 3933 } 3934 } 3935 3936 $num_pages = count( $pages ); 3935 3937 for ( $i = 0; $i < $num_pages; $i++ ) { 3936 if ( in_array($pages[$i]->ID, $excludes) ) 3937 unset($pages[$i]); 3938 if ( in_array( $pages[$i]->ID, $exclude ) ) { 3939 unset( $pages[$i] ); 3940 } 3938 3941 } 3939 3942 } -
trunk/tests/phpunit/tests/post/getPages.php
r27755 r27767 237 237 _unregister_post_type( $type ); 238 238 } 239 240 function test_exclude_tree() { 241 $post_id1 = $this->factory->post->create( array( 'post_type' => 'page' ) ); 242 $post_id2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $post_id1 ) ); 243 $post_id3 = $this->factory->post->create( array( 'post_type' => 'page' ) ); 244 $post_id4 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $post_id3 ) ); 245 246 $all = get_pages(); 247 248 $this->assertCount( 4, $all ); 249 250 $exclude1 = get_pages( "exclude_tree=$post_id1" ); 251 $this->assertCount( 2, $exclude1 ); 252 253 $exclude2 = get_pages( array( 'exclude_tree' => $post_id1 ) ); 254 $this->assertCount( 2, $exclude2 ); 255 256 $exclude3 = get_pages( array( 'exclude_tree' => array( $post_id1 ) ) ); 257 $this->assertCount( 2, $exclude3 ); 258 259 $exclude4 = get_pages( array( 'exclude_tree' => array( $post_id1, $post_id2 ) ) ); 260 $this->assertCount( 2, $exclude4 ); 261 262 $exclude5 = get_pages( array( 'exclude_tree' => array( $post_id1, $post_id3 ) ) ); 263 $this->assertCount( 0, $exclude5 ); 264 265 $post_id5 = $this->factory->post->create( array( 'post_type' => 'page' ) ); 266 $post_id6 = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $post_id5 ) ); 267 268 $exclude6 = get_pages( array( 'exclude_tree' => array( $post_id1, $post_id3 ) ) ); 269 $this->assertCount( 2, $exclude6 ); 270 } 239 271 }
Note: See TracChangeset
for help on using the changeset viewer.