I want to display a total number of customer reviews on the homepage, I have tried this method:
<?php
$args = array(
'status' => 'approve',
'post_status' => 'publish',
'post_type' => 'product'
);
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );
$count = get_comment_count($comments);
?>
<span class="total_reviews">
<?php echo $count['approved'] . ' reviews' ?>
</span>
But isn't working like I want! for example, I have 4 reviews comments and this code show only (1 reviews) instead of (4 reviews).
About the average, I don't have any idea of how it's work on the homepage, I just know how to implement this on a single product page by using this code below:
$average = $product->get_average_rating();
But, this code is only for a single product average ratings, not a global average of all reviews as I would like.
Any help is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…