From 4d2e474a0fdd6209f752453c7ee23903b4e63ec1 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 29 Apr 2009 21:01:51 +0000 Subject: [PATCH] Allow for non-contiguous array indices. Props hailin. fixes #9670 git-svn-id: http://svn.automattic.com/wordpress/trunk@11130 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/template.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 955e9675dc..2a3b3e175c 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -510,11 +510,13 @@ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $select // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) $checked_categories = array(); - for ( $i = 0; isset($categories[$i]); $i++ ) { - if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) { - $checked_categories[] = $categories[$i]; - unset($categories[$i]); - } + $keys = array_keys( $categories ); + + foreach( $keys as $k ) { + if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { + $checked_categories[] = $categories[$k]; + unset( $categories[$k] ); + } } // Put checked cats on top