Problem:
How to filter the addition of numeric values in a search
Solution:
Make sure that you put the sum of the numeric values after the view.
Sample code to get started on how to create a shortcode for that:
/** * Register shortcode to add field values for each item in loop to give total (after loop) */ add_shortcode('sum-item', function ($atts=[],$content = null) { $atts = shortcode_atts( array( 'total' => null ), $atts ); static $running = 0; $output = ""; if ( ! is_null( $content ) ) { $content = do_shortcode( ltrim($content) ); if ( is_numeric( $content ) ) { $running += $content; } } if ( ! is_null( $atts['total'] ) ) { $output = $running; } return $output; });
How to use the shortcode:
/** An example of usage in the output of a View: */ [wpv-items-found] [wpv-post-link] [sum-item] [types field="number-field"][/types][/sum-item] [sum-item total=true] [/wpv-items-found]
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.
This topic contains 5 replies, has 2 voices.
Last updated by 2 years, 10 months ago.
Assisted by: Christopher Amirian.