diff --git a/wp-admin/edit-post-rows.php b/wp-admin/edit-post-rows.php index 591b9b463e..0906b68c8b 100644 --- a/wp-admin/edit-post-rows.php +++ b/wp-admin/edit-post-rows.php @@ -22,6 +22,14 @@ if ( have_posts() ) { $bgcolor = ''; add_filter('the_title','wp_specialchars'); + +// Create array of post IDs. +$post_ids = array(); +foreach ( $wp_query->posts as $a_post ) + $post_ids[] = $a_post->ID; + +$comment_pending_count = get_pending_comments_num($post_ids); + while (have_posts()) : the_post(); $class = 'alternate' == $class ? '' : 'alternate'; global $current_user; @@ -113,7 +121,7 @@ foreach($posts_columns as $column_name=>$column_display_name) { ?>
ID ); + $left = isset($comment_pending_count) ? $comment_pending_count[$post->ID] : 0; $pending_phrase = sprintf( __('%s pending'), number_format( $left ) ); if ( $left ) echo ''; diff --git a/wp-admin/includes/comment.php b/wp-admin/includes/comment.php index f29d5ec0f4..8a47fe6d2f 100644 --- a/wp-admin/includes/comment.php +++ b/wp-admin/includes/comment.php @@ -66,9 +66,28 @@ function get_comment_to_edit( $id ) { function get_pending_comments_num( $post_id ) { global $wpdb; - $post_id = (int) $post_id; - $pending = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '0'", $post_id) ); - return $pending; + + $single = false; + if ( !is_array($post_id) ) { + $post_id = (array) $post_id; + $single = true; + } + $post_id = array_map('intval', $post_id); + $post_id = "'" . implode("', '", $post_id) . "'"; + + $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_N ); + + if ( empty($pending) ) + return 0; + + if ( $single ) + return $pending[0][1]; + + $pending_keyed = array(); + foreach ( $pending as $pend ) + $pending_keyed[$pend[0]] = $pend[1]; + + return $pending_keyed; } // Add avatars to relevant places in admin, or try to