Home Forums General Issues How to get field types in acf/save_post action


How to get field types in acf/save_post action

  • Hi there,

    I have a field groups that was star rating fields. I am using the star rating plugin from here:

    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:


    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') {
        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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.