I am not sure to understand your goal:
- do you want to perform mathematical operations with numeric values, which are stored in a Custom Field?
- or do you want to count how many instances of a certain Field exist and are filled out with a value across a Post Type?
- or do you want to do both? ?
Basically, Toolset is not the tool to perform any form of calculations.
A little restricted exception provides HTML conditional in which you can make basic calculations to compare then the value to something else:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/#using-fields-with-math-operators
But this is only possible within a condition.
Now, to perform mathematical operations with numeric values, which are stored in a Custom Field you can use this steps as reference:
- Register the custom shortcode "calculate":
/**
* Add custom shortcode to perform calculations with Types fields
*
* attribute 'round' for decimal places, defaults to zero
*/
add_shortcode('calculate', function( $atts = [], $content=null ) {
$atts = shortcode_atts([ 'round' => 0 ], $atts );
$content = strip_tags( wpv_do_shortcode($content) );
$content = eval("return $content;");
return round($content, $atts['round']);
});
- Then use it like this:
[calculate round=2][types field="weight"]*[types field="unit-price"]/100[/calculate]
Or, another method:
- Register this 2 ShortCode:
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, Register those ShortCodes in Views > Settings > Compatibility > 3rd Party ShortCodes
- Use the ShortCodes in a View as this:
<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]
Instead, to calculate how many instances of a field are there, you can use a simple count() on the get_post_meta() of the field in question.
This is custom code that we cannot assist fully.
If you require add-on functionality to Toolset with Custom Code, you may be interested in the Contractors List:
https://toolset.com/contractors/