
Hi there,
I have a field groups that was star rating fields. I am using the star rating plugin from here: https://github.com/kevinruscoe/acf-star-rating-field
Everything is working fine but I have several star rating fields in a field group and I have one field called total_rating which I aim to take the average of all the other star rating fields in the field group.
So for example, here are my fields:
cleanliness
check-in/check-out
breakfast
wifi
total_rating
Now, when I set all the fields except thetotal_rating
field, I would like to assign a value to the total_rating
field. I am using the acf/save_post action
. Currently, I have this code:
add_action('acf/save_post', 'save_post', 20);
function save_post($post_id) {
if (get_post_type($post_id) != 'post') {
return;
}
error_log($post_id);
error_log( print_r( $_POST['acf'], true ) );
}
Inside the function, I would like to be able to filter all the fields and loop through all five_star_rating
fields so that I can could and get the average of the five_star_rating
but I am not sure how to do it because the $_POST['acf']
only includes the field names and their respective values.
Thank you!
Please consider this solved. I was already able to find a solution to this.