Exclude custom comment type from count in WordPress
If you’ve added a new type of comments in WordPress, but do not want them to appear in the normal comments list, and also exclude them from the comments count, then do the following:
1. To exclude custom type comments from the normal list:
Add type argument to wp_list_comments function (usually it’s in comments.php file of the active theme) .
wp_list_comments(array('type' => 'comment'));
2. To exclude custom type comments from the post comments count (comment_count):
Add to functions.php code below:
add_action('wp_update_comment_count', 'sniff_update_comment_count');
function sniff_update_comment_count($post_id) {
global $wpdb;
$post_id = (int)$post_id;
if ( !$post_id )
return false;
if ( !$post = get_post($post_id) )
return false;
$new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*)
FROM $wpdb->comments
WHERE comment_post_ID = %d AND comment_approved = '1' AND comment_type != 'community_review' ", $post_id) );
$wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
clean_post_cache( $post );
}
Change community_review to your custom comment type name in comment_type != ‘community_review’ (line 12) which you want to exclude.
That’s all.