Human friendly WordPress Automation
Calculated Fields for ACF supports working with repeater fields (requires Advanced Custom Fields Pro) and group fields.
If a formula expression is added to a sub field inside a repeater or group field, any field name in the formula expression is assumed to be another sub field in the same repeater or subgroup.
Screen shot from a repeater field. Any formula expression in field “p1” or “p2” can refer to the “price” field. The same logic applies for group fields.
A formula expression in one of the sub fields in a repeater or group field may refer to fields on the parent level using the prefix “parent” and a dot:
The expression “parent.prefix” is a legal expression and can be used together with functions and operators just like any other field/variable expression.
On the parent level, the values in a repeater field can be accessed using one of the aggregation functions.
To make the aggregation function work out, we’ve bended the normal rules of valid expressions a little bit. Anything after the dot (.) in the aggregate expression is an expression in itself that is evaluated for each row in the repeater. Therefore it’s perfectly OK to write a formula like:
This expression will walk over all lines in the “orderlines” repeater field, evaluate the expression “price * amount” and return the sum of all lines.
The side effect of this is that when working with aggregate functions, parentheses can not be used in the expression. If you need to aggregate a more complex calculation, you should add an extra field in the repeater group and let the aggregate function work on this extra field.
Powered by BetterDocs
Your email address will not be published. Required fields are marked *
Yes, sign me up for informational and marketing emails from wundermatics.com
Save my name, email, and website in this browser for the next time I comment.