Display Comment Count

This snippet displays the total number of comments for a post, excluding pingbacks and trackbacks.

PHP

function get_comment_count($post_id) {
    $comments = get_comments(array(
        'post_id' => $post_id,
        'status' => 'approve',
        'type' => 'comment'
    ));
    return count($comments);
}

// Usage
echo 'This post has ' . get_comment_count(get_the_ID()) . ' comments.';

Snippet Feedback

Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY

1 Views

Tags

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.