Calculated fields for ACF
Adds a formula fields ot Advanced Custom Fields that allows you to perform simple math based on field values. Calculations are updated dynamically via ajax while editing a post on the backend post editor as well as on front end forms. Requirements Calculated fields requires Advanced Custom Fields 5.
Adds a formula fields ot Advanced Custom Fields that allows you to perform simple math based on field values. Calculations are updated dynamically via ajax while editing a post on the backend post editor as well as on front end forms.
Requirements
Calculated fields requires Advanced Custom Fields 5.0 or later and works with Pro as well as the standard version.
Frontend forms
Beginning in version 1.2.3, Calculated fields for ACF supports frontend forms created using the acf_form() function (built in to Advanced Custom Fields).
Formulas
Calculated fields adds a new setting “Formula” to the the ACF field editor. Formulas supports referring to other fields in the same Field group using the field name. If a formula is added to a sub field inside a repeater field, the name refers to another sub field in the same repeater.
A sub field inside a repeater field can also refer to a parent field using the “parent.”” prefix.
A formula can contain the basic mathematical operations: plus (+), minus (-), multiply (*), division (/) and power of (^). Formulas can also contains functions like sin, cos, arcsin, log, ln, sqrt, abs. Parentheses are supported.
If an expression can’t be evaluated due to invalid syntax or referring to undefined field names, it will silently return zero.
Examples of valid expressions (note, no equal sign at the beginning):
- fieldA * 2
- fieldA * fieldB
- abs(fieldA) * (2 + sqrt(fieldB))
- amount * parent.price
Conditional operators
An expression can also contain a conditional expression that will return either 0 or 1. The supported operators are:
- Equals (==) – Returns 1 when two values are equal, 0 otherwise
- Not equals (!=) – Returns 1 when two values are not equal, 0 otherwise
- Greater than (>) – Returns 1 when the first operand is greater than the second, 0 otherwise
- Greater than or equal (>=) – Returns 1 when the first operand is greater than or equal to the second, 0 otherwise