Open MPHood opened 5 years ago
Hi!
Do you mean that using {field:field_name[sub_field_name]}
doesn't work with calculated fields?
Thats whats happening:
If I place a calculated field outside the group, it works.
What I´m trying to do:
function ersparnis_berechnen3() {
// I WANT TO GET THE VALUES OF THE (SUB)FIELDS INSIDE THE ACF GROUP - DO I NEED to use something else than af_get_field in order to get the field values that are inside an ACF Group?
$val1 = af_get_field( 'verbrauch11]' );
$val2 = af_get_field( 'verbrauch_Kopie1' );
$val3 = af_get_field( 'verbrauch31' );
$val4 = af_get_field( 'verbrauch41' );
// Calculate the sum of the field values
$verbrauchb = $val1 + $val2 + $val3 + $val4;
// Calculate the sum of the current field values
$sparb = $verbrauchb * 0.09;
// Display the sum in the calculated field
return ' Bis zu ' . $sparb . ' Euro/Jahr! '; }
add_filter( 'af/field/calculate_value/name=spar2', 'ersparnis_berechnen3', 10, 0 );
The Code works if the Calculated filed is outside the ACF group.
I hope you can understand my problem.
Greets
I think I understand now!
The UI currently won't work if you place a calculated field inside a group. What should work though is the af/field/calculate_value
filter you're currently using.
If you want to use af_get_field
to get values of fields inside groups you'll need to fetch the full group using af_get_field( GROUP_FIELD_NAME )
. You will then get an array containing the values of all subfields.
Calculated fields dont work if the fields arr inside an acf group.
Is there any workaround?