Calculate sum of Custom Fields in a View, as in += PHP operator.

Register this 2 ShortCodes:

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');</code>

Register those ShortCodes in Views > Settings > Compatibility > 3rd Party ShortCodes

Use the ShortCodes in a View as this:

<wpv-loop>
    
    [add-to-total]
      
    [/add-to-total]
</wpv-loop>
[show-total]

Support Thread Example

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments