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
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
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users