Title: wp_dashboard_recent_comments
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_dashboard_recent_comments( int $total_items = 5 ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#wp--skip-link--target)

Show Comments section.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#parameters)󠁿

 `$total_items`intoptional

Number of comments to query.

Default:`5`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#return)󠁿

 bool False if no comments were found. True otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#source)󠁿

    ```php
    function wp_dashboard_recent_comments( $total_items = 5 ) {
    	// Select all comment types and filter out spam later for better query performance.
    	$comments = array();

    	$comments_query = array(
    		'number' => $total_items * 5,
    		'offset' => 0,
    	);

    	if ( ! current_user_can( 'edit_posts' ) ) {
    		$comments_query['status'] = 'approve';
    	}

    	$comments_count = 0;
    	do {
    		$possible = get_comments( $comments_query );

    		if ( empty( $possible ) || ! is_array( $possible ) ) {
    			break;
    		}

    		foreach ( $possible as $comment ) {
    			if ( ! current_user_can( 'edit_post', $comment->comment_post_ID )
    				&& ( post_password_required( $comment->comment_post_ID )
    					|| ! current_user_can( 'read_post', $comment->comment_post_ID ) )
    			) {
    				// The user has no access to the post and thus cannot see the comments.
    				continue;
    			}

    			$comments[]     = $comment;
    			$comments_count = count( $comments );

    			if ( $comments_count === $total_items ) {
    				break 2;
    			}
    		}

    		$comments_query['offset'] += $comments_query['number'];
    		$comments_query['number']  = $total_items * 10;
    	} while ( $comments_count < $total_items );

    	if ( $comments ) {
    		echo '<div id="latest-comments" class="activity-block table-view-list">';
    		echo '<h3>' . __( 'Recent Comments' ) . '</h3>';

    		echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
    		foreach ( $comments as $comment ) {
    			_wp_dashboard_recent_comments_row( $comment );
    		}
    		echo '</ul>';

    		if ( current_user_can( 'edit_posts' ) ) {
    			echo '<h3 class="screen-reader-text">' .
    				/* translators: Hidden accessibility text. */
    				__( 'View more comments' ) .
    			'</h3>';
    			_get_list_table( 'WP_Comments_List_Table' )->views();
    		}

    		wp_comment_reply( -1, false, 'dashboard', false );
    		wp_comment_trashnotice();

    		echo '</div>';
    	} else {
    		return false;
    	}
    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/dashboard.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/dashboard.php#L1080)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/dashboard.php#L1080-L1148)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#related)󠁿

| Uses | Description | 
| [_wp_dashboard_recent_comments_row()](https://developer.wordpress.org/reference/functions/_wp_dashboard_recent_comments_row/)`wp-admin/includes/dashboard.php` |

Outputs a row for the Recent Comments widget.

  | 
| [_get_list_table()](https://developer.wordpress.org/reference/functions/_get_list_table/)`wp-admin/includes/list-table.php` |

Fetches an instance of a [WP_List_Table](https://developer.wordpress.org/reference/classes/wp_list_table/) class.

  | 
| [wp_comment_reply()](https://developer.wordpress.org/reference/functions/wp_comment_reply/)`wp-admin/includes/template.php` |

Outputs the in-line comment reply-to form in the Comments list table.

  | 
| [wp_comment_trashnotice()](https://developer.wordpress.org/reference/functions/wp_comment_trashnotice/)`wp-admin/includes/template.php` |

Outputs ‘undo move to Trash’ text for comments.

  | 
| [post_password_required()](https://developer.wordpress.org/reference/functions/post_password_required/)`wp-includes/post-template.php` |

Determines whether the post requires password and whether a correct password has been provided.

  | 
| [get_comments()](https://developer.wordpress.org/reference/functions/get_comments/)`wp-includes/comment.php` |

Retrieves a list of comments.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#)

| Used by | Description | 
| [wp_dashboard_site_activity()](https://developer.wordpress.org/reference/functions/wp_dashboard_site_activity/)`wp-admin/includes/dashboard.php` |

Outputs the Activity widget.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_comments/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.8.0](https://developer.wordpress.org/reference/since/3.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dashboard_recent_comments%2F)
before being able to contribute a note or feedback.