Hello,
I have a group of repeating fields.
Inside I have a field called Amount : [types field='note-montant' format='FIELD_VALUE' separator=', ']
I would like to make an addition to calculate the total amount.
Thank you
Hello, at this time there is no feature that will allow you to customize the repeating field group display in wp-admin or insert calculated values in the repeating field group editor. You may be able to accomplish something like this using a separate custom field on the main post (not in the RFG editor panel). With custom code you could calculate the values of all the repeating field group fields and update the main post custom field whenever a RFG is added, removed, or modified, but this is outside the scope of support we provide here in the forums. A skilled developer may be able to set this up for you. We have a portal available where you can connect with developers who provide solutions like this: https://toolset.com/contractors.
Sorry we did not understand each other.
I wish to have the total of the amounts in front office.
I tried this as a function:
add_shortcode ('calculate', 'calculate_shortcode');
function calculate_shortcode ($ atts, $ content = null) {
$ content = wpv_do_shortcode ($ content);
$ content = @eval ("return $ content;");
return round ($ content);
}
and in my view:
[calculate] [types field = 'note-amount' format = 'FIELD_VALUE'] [/ types] + [types field = 'note-amount' format = 'FIELD_VALUE'] [/ types] [/ calculate]
But it's a repeated field group.
How to do ?
Okay I understand better now, thank you. You won't be able to use the calculate shortcode here, because the values all come from different posts in a loop. The calculate shortcode only works if the values can be accessed at the same time. Instead, you could write a custom shortcode that performs this calculation and returns the total. Repeating field groups (RFGs) are basically child posts, so you can use the toolset_get_related_posts API to query all the child RFGs, then use get_post_meta to get the custom field values. Custom fields are stored in the database as 'wpcf-fieldslug'. You can find some documentation about these APIs here:
https://codex.wordpress.org/Shortcode_API
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
https://developer.wordpress.org/reference/functions/get_post_meta/