I am trying to build a review system using ACF.
Reviews (custom post type) is attached to a Product (custom post type). A review is composed of 4 items (integer). For each review, I’ve created a calculated field : (item 1 + item 2 + item 3 + item 4) / 4 = customer rating.
That works well.
Now, I am trying to display (using a shortcode) the global average rating that would consist of : (customer rating 1 + custom rating 2 + … + customer rating n) / n
Any idea on how to achieve this ?
Did you ever figure this out? I’m trying to do the same thing.
One way is to set a field called avg rating that can hold num of reviews and total score on the post that the reviews are attached to and whenever a new review is approved to hook into it with acf/save_post (https://www.advancedcustomfields.com/resources/acf-save_post/)
and update the field of the main post with the new values adding +1 to total and +customer rating to the total score.
then on shortcode just do the simple total/num_reviews