I have a custom repeater group. In the group is a number field. Now, in the post type I have 4 sets. The number fields are all 5.
I want to have a view that will add all those number fields together and give the result. I cannot figure out how to do this. The view is looping through the fields and outputting in
tags. But I need them to combine as one output. I know sometimes you can have the view output with a comma separator. Is there any way to use this to spit out all of my custom field values so I can do some math on them?
I am using this as an example: https://toolset.com/forums/topic/math-with-custom-fields-values/#post-509325
Thanks in advance.
Hello,
There isn't such a built-in feature within Views plugin, and it needs custom codes, you can try this:
1) put the custom PHP codes into your theme file functions.php:
add_shortcode('calculate', function( $atts = [], $content=null ) {
$atts = shortcode_atts([ 'round' => 0 ], $atts );
$content = wpv_do_shortcode($content);
$content = eval("return $content;");
return round($content, $atts['round']);
});
https://toolset.com/forums/topic/math-with-custom-fields-values/#post-509325
2) Create a view list your custom repeater group, in the section "Loop Editor", use above custom shortcode like this:
...
<!-- wpv-loop-start -->
[calculate round=2]<wpv-loop>[wpv-item index=1][types field="num1"][/types][wpv-item index=other]+[types field="num1"][/types]</wpv-loop>[/calculate]
<!-- wpv-loop-end -->
...
It will be able to output the results as math calculation.
More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-item
Used in the loop. Sets a condition to be met for subsequent lines in the loop to be executed.