Average Of Sub-fields Value In ACF Repeater Field

Share Now

<?php
                
$count = count(get_field('ss_results'));

$tasks = get_sub_field('ss_results'); $totaltasks = count($tasks);
$totaltaskpercentage = 0;

while ( have_rows('ss_results') ) : the_row(); 
$totaltaskpercentage += intval( get_sub_field('test_score'));
endwhile; 

$grouptaskpercentage = $totaltaskpercentage / $totaltasks;
$final_result = round($grouptaskpercentage)/$count;

 ?>
Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert