Hi, I have created a custom field for a custom post type called weight.
I would like to display the total combined weight of all my posts. There is an undetermined number of posts and i would like this to update every time a new post is created.
I don't need to store the value anywhere. I am just looking to have it calculated and displayed via the views interface.
I saw this (https://toolset.com/forums/topic/calculator/) but it works for 1+2+3. I have 1+2+3+ ....
Hello,
There isn't such a built-in feature within Views plugin, as you mentioned above, the solution of another thread only works for field1+ field2+ field3
https://toolset.com/forums/topic/calculator/
You need to specific the field shortcodes insider shortcode [wpv-calculate] ... [/wpv-calculate]
And I don't think it is a good idea to sum all custom fields, since there might be some other custom fields/hidden fields in single post, it will conduct other unexpected problem if you setup custom shortcodes to sum the result like this:
field1+field2+field3+ ....
I was able to figure it out.
I used
[wt-calc]
<wpv-loop>
[types field='deadweight' output='raw'][/types] + // this will loop through all the instances of the field.
</wpv-loop>
0 // to take care of the last +
[/wt-calc]