Home › Forums › Add-ons › Repeater Field › Sum Values of Sub Fields in Nested Repeater › Reply To: Sum Values of Sub Fields in Nested Repeater
Here is the code I came up with, just in case anyone else finds it useful:
<?php
$tasks = get_sub_field('project_task'); $totaltasks = count($tasks);
$totaltaskpercentage = 0;
while ( have_rows('project_task') ) : the_row();
$totaltaskpercentage += intval( get_sub_field('project_task_percentage'));
endwhile;
$grouptaskpercentage = $totaltaskpercentage / $totaltasks;
echo round($grouptaskpercentage);
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.