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]