diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index cac03b1fe3630..35402023e8f13 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -1076,7 +1076,8 @@ function wp_dashboard_recent_comments( $total_items = 5 ) { $comments_count = 0; do { - $possible = get_comments( $comments_query ); + $fetch_count = $comments_query['number'] - $comments_query['offset']; + $possible = get_comments( $comments_query ); if ( empty( $possible ) || ! is_array( $possible ) ) { break; @@ -1091,8 +1092,8 @@ function wp_dashboard_recent_comments( $total_items = 5 ) { continue; } - $comments[] = $comment; - $comments_count = count( $comments ); + $comments[] = $comment; + ++$comments_count; if ( $comments_count === $total_items ) { break 2; @@ -1101,7 +1102,7 @@ function wp_dashboard_recent_comments( $total_items = 5 ) { $comments_query['offset'] += $comments_query['number']; $comments_query['number'] = $total_items * 10; - } while ( $comments_count < $total_items ); + } while ( $comments_count < $total_items && count( $possible ) === $fetch_count ); if ( $comments ) { echo '