Skip Navigation

[Résolu] Adding all values for a specific custom field

This support ticket is created Il y a 5 années et 8 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par Adrian Il y a 5 années et 8 mois.

Assisté par: Luo Yang.

Auteur
Publications
#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]