Support

Account

Home Forums General Issues how to make a calculated fields in ACF

Unread

how to make a calculated fields in ACF

  • Hello everybody
    i want to create a field for average rate with other fields
    All fields are in one field group
    For Example
    field1 = 70
    field2 = 60
    field3 = 80
    field4 = 0
    field5 = 0
    field6_total = 70

    im tried with this code but It didn’t work for me

    
    function my_acf_save_post( $post_id ) {
        
    $score = get_field('score'); // score فعال کردن گروه
    $total_score = $score['field6_total'];
    $v1f = $score['field1']; 
    $v2f = $score['field2']; 
    $v3f = $score['field3']; 
    $v4f = $score['field4'];
    $v5f = $score['field5'];
    $array_total_average = array($v1f,$v2f,$v3f,$v4f,$v5f);
    $array_total_average = array_filter($array_total_average);
    $total_score_average =array_sum($array_total_average) / count($array_total_average);
        
    update_field($total_score, $total_score_average, $post_id);
    	
    }
    
    add_action('acf/save_post', 'my_acf_save_post', 20);
    

    Is there a function that exists for this, or one that I can modify to make this work?

Viewing 1 post (of 1 total)

The topic ‘how to make a calculated fields in ACF’ is closed to new replies.