• jgateman

    (@jgateman)


    I am trying to figure out a way to calculate the sum of an ACF number field within a loop and return that value as a single number.

    I have a field called ‘calories’ inside a CPT. There is about a dozen posts each with a calorie value that I need to add together.

    Is this possible using the [calc] shortcode? If so how do I write that snippet? I haven’t had any luck trying to get it to work.

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter jgateman

    (@jgateman)

    Figured out a round about solution that works.

    I run the loop in an ACF text field named ‘sums:

    [loop type=move author=this][field calories]+[/loop]

    I then run the calc on the page:

    [calc][field sums length=’-1′][/calc]

    The length=’-1′ removes the last + from the end of the loop which was breaking the [calc]

    I can then further isolate specific date ranges if I want to display the sum from just this week for example:

    [loop type=move author=this][if field=date after=’last Sunday’][field calories]+[/if][/loop]

Viewing 1 replies (of 1 total)
  • The topic ‘Calculate sum from loop’ is closed to new replies.