Get total number of comments from posts in a specific custom taxonomy

You’ll need to loop through your posts, use get_comments_number() to get the number of comments for each post, and then accumulate the total number of comments in a separate variable. e.g.:

<?php
$features_comment_count = 0;

if ( have_posts() ) : while ( have_posts() ) : the_post();

$features_comment_count += get_comments_number();

endwhile; endif;
?>

(I’ll assume that you know how to custom-query your posts, and can adapt the above code as necessary.)

If you want to count the comments before outputting post content, then simply run the above loop, and then rewind posts using rewind_posts():

<?php rewind_posts(); ?>

Then, you can output your posts loop as per normal.

Leave a Comment