antonM-7
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
Is there any way to calculate sum of values of particular field in picked items?
Started by: antonM-7
in: Toolset Professional Support
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: |
2 | 3 | 5 years, 6 months ago |