From ef738c9b9b18af5dd9f0222da23c87150276d5a0 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 29 Apr 2009 21:01:51 +0000 Subject: [PATCH] Allow for non-contiguous array indices. Props hailin. fixes #9670 git-svn-id: https://develop.svn.wordpress.org/trunk@11130 602fd350-edb4-49c9-b593-d223f7449a82 --- 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