I need to display a review count for all products in a specific category. The following code works to count all reviews (as comments) for all products, however get_comments() doesn't seem to be set up to allow taxonomy queries...
function rnr_colors_review_count() {
$args = array(
'post_type' => 'product', //Post type
'status' => 'approve',
'count' => 'true'
//I would like to insert a taxonomy arg here, but may need another solution.
);
$comments_count = get_comments($args);
echo 'Total Comments= ' . $comments_count;
}
You need to use a custom lightweight SQL query. I have embedded that Sql query in the function below, with an argument: the product category term slug.
The function:
Code goes in functions.php file of your child theme (or in a plugin). Tested and work.
Usage example displaying the reviews count for "accessories" product category term slug: