how to make a calculated fields in ACF
Question
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');
$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?
i used a advanced custom field plugin
0
custom-field, functions, plugins, save-post
4 years
2020-03-29T08:51:31-05:00
2020-03-29T08:51:31-05:00 0 Answers
184 views
0
Leave an answer