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

    echo ‘Total Value: ‘. $factorTotal .’ $’;

    I need it to calculate the sum of custom field ‘price’ that is in all of my posts