Skip Navigation

[Resolved] Addition Group Repeating Fields

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#644218
total.png

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

#644861

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.

#652318
note.png

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 ?

#652821

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/