Problem: I would like to be able to calculate the total sum of the custom field values in a View.
Solution: There's nothing built-in to Toolset that will perform summations like this, it requires custom code. This solution is only for simple cases. Add to your child theme's functions.php file:
global $total; function add_total_shortcode($atts, $content = '') { global $total; $total += wpv_do_shortcode($content); } add_shortcode('add-to-total', 'add_total_shortcode'); function show_total_shortcode() { global $total; $totalNew = $total; $total = 0; return $totalNew; } add_shortcode('show-total', 'show_total_shortcode');
Then in the View's Loop, duplicate the custom field shortcode and wrap it in the shortcode add-to-total, and use the show-total shortcode to display the total value:
<wpv-loop> [types field="your-numeric-field" output="raw"][/types] [add-to-total] [types field="your-numeric-field" output="raw"][/types] [/add-to-total] </wpv-loop> [show-total]
Tis is a simple solution that only works in one column of a View, and only works with a simple numeric field. More complex cases will require your own custom code modifications.
Relevant Documentation:
https://toolset.com/forums/topic/nested-view-with-conditional-sums/
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 5 years, 3 months ago.
Assisted by: Christian Cox.