# Unanswered Comments Widget

> Adds a dashboard widget listing recent approved comments from readers that nobody on your team has replied to yet, so questions do not go unanswered.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Tags: dashboard-widget, comments, engagement
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/dash-unanswered-comments-widget/

## Code

```php
add_action( 'wp_dashboard_setup', function () {
    if ( ! current_user_can( 'moderate_comments' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_unanswered_comments', 'Unanswered comments', function () {
        global $wpdb;

        $staff = get_users( array( 'capability' => 'edit_posts', 'fields' => 'ID' ) );
        $staff = $staff ? implode( ',', array_map( 'absint', $staff ) ) : '0';

        $comments = $wpdb->get_results( $wpdb->prepare(
            "SELECT c.comment_ID, c.comment_post_ID, c.comment_author, c.comment_content, c.comment_date_gmt FROM {$wpdb->comments} c
            WHERE c.comment_approved = '1' AND c.comment_type IN ('comment','') AND c.user_id NOT IN ($staff) AND c.comment_date_gmt >= %s
            AND NOT EXISTS ( SELECT 1 FROM {$wpdb->comments} r WHERE r.comment_parent = c.comment_ID AND r.user_id IN ($staff) )
            ORDER BY c.comment_date_gmt DESC LIMIT 8",
            gmdate( 'Y-m-d H:i:s', time() - 60 * DAY_IN_SECONDS )
        ) );

        if ( ! $comments ) {
            echo '<p>Every recent comment has a reply.</p>';
            return;
        }

        echo '<ul>';
        foreach ( $comments as $comment ) {
            printf(
                '<li style="margin-bottom:10px"><strong>%s</strong> on <a href="%s">%s</a><br>%s<br><a href="%s">Reply</a> <small>&middot; %s ago</small></li>',
                esc_html( $comment->comment_author ),
                esc_url( get_permalink( $comment->comment_post_ID ) ),
                esc_html( get_the_title( $comment->comment_post_ID ) ),
                esc_html( wp_trim_words( $comment->comment_content, 18 ) ),
                esc_url( admin_url( 'edit-comments.php?p=' . (int) $comment->comment_post_ID . '#comment-' . (int) $comment->comment_ID ) ),
                esc_html( human_time_diff( strtotime( $comment->comment_date_gmt . ' UTC' ) ) )
            );
        }
        echo '</ul>';
    } );
} );
```

## Notes

A reply from any user who can edit posts counts as answered; looks at the last 60 days.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Unanswered Comments Widget" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
