Home › Forums › Feature Requests › ACF total sum › Reply To: ACF total sum
i comed up with this code, but it only calculates the sum of the posts on that page or category
$factorTotal = 0;
$factorCount = 0;
while ( have_posts() ) : the_post();
$factorI = get_field(‘price’, $post->ID);
if($factorI){ // Only if it exists
$factorTotal += $factorI; // Add it
$factorCount++; // Count it
} // end if
endwhile;
echo ‘Total Value: ‘. $factorTotal .’ $’;
I need it to calculate the sum of custom field ‘price’ that is in all of my posts
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.