Skip Navigation

[Resolved] Adding all values for a specific custom field

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Adrian 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1224802

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+ ....

#1224829

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+ ....

#1225185

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]