Actually … this describes my question better: {field:group_name[sub_group_name[sub_field]]}
Hi!
As you’ve noticed the plugin currently doesn’t support nested group fields. I know it’s annoying but ACF group fields are pretty hard to interact with so I opted to add the single-level group include for convenience.
It’s possible to add your own merge tags with a little bit of code and in that way you could create one for your specific use case.
Something like this should work but I haven’t had the chance to test it:
function nested_group_merge_tag( $output, $tag )
if ( 'nested_group_field' != $tag ) {
return $output;
}
$top_level_group_name = 'group1';
$second_level_group_name = 'group2';
$sub_field_name = 'field';
$top_level_value = af_get_field( $top_level_group_name );
return $top_level_value[ $second_level_group_name ][ $sub_field_name ];
}
add_filter( 'af/merge_tags/resolve', 'nested_group_merge_tag', 10, 2 );
So change the three variables to your field names. 🙂
I added a {
at the end of line 1, so the code now looks like this:
function nested_group_merge_tag( $output, $tag ) {
if ( 'nested_group_field' != $tag ) {
return $output;
}
$top_level_group_name = 'group1';
$second_level_group_name = 'group2';
$sub_field_name = 'field';
$top_level_value = af_get_field( $top_level_group_name );
return $top_level_value[ $second_level_group_name ][ $sub_field_name ];
}
add_filter( 'af/merge_tags/resolve', 'nested_group_merge_tag', 10, 2 );
But still … after correcting the code, it still does not work “out-of-the-box” after changing the 3 variables.
Also … what format do I use in the form notifications?
Something like this? {field:group_name[sub_group_name][sub_field]}
Sorry, didn’t make that entirely clear. You would use “{nested_group_field}” to show the value. You can change what tag you want at line 2.
Thank you, Fabian!
That helped indeed … it works now.
“nested_group_field” can also be “any_given_name” and when used in the form notification as “{any_given_name}” it displays the field in the subgroup.
For others with the same issue: use the code above in the functions.php or another included_once template.