Display nested ACF subfield from group within group in WordPress frontend

I’m working with WordPress and Advanced Custom Fields plugin. I can easily display regular subfields from groups, but I’m stuck when trying to show a subfield that’s inside another group.

My field structure looks like this:

Training (Group Field)
____Training Name (Text Field)
____Training Info (Group Field)
________Training Summary (Text Field)

I can display the Training Name without issues using this code:

<?php $myTraining = get_field('training'); ?>
<?php if ( $myTraining ) : ?>
<h3 class="training-name"><?php echo $myTraining['training_name']; ?></h3>
<?php endif; ?>

But I can’t figure out how to access the Training Summary field that’s nested inside the Training Info group. What’s the proper way to reach that deeply nested field? Do I need to use multiple variables or is there a different approach?

Oh interesting! Are you using any repeater fields inside those groups? Nesting gets tricky with repeaters. Also, does everything look right when you var_dump the $myTraining array to check the actual structure?

To access the nested field, you will need to follow the structure by referencing both group levels. Start with the ‘training’ field, then navigate to ‘training_info’, and finally pull out ‘training_summary’ from there. Here’s how you can implement it:

<?php $myTraining = get_field('training'); ?>
<?php if ( $myTraining && isset($myTraining['training_info']['training_summary']) ) : ?>
<p class="training-summary"><?php echo $myTraining['training_info']['training_summary']; ?></p>
<?php endif; ?>

Including isset() will help you avoid errors in case those fields do not exist.

try using $myTraining['training_info']['training_summary']. you can chain the array keys for nested groups in ACF. just make sure to reference both the outer and inner groups correctly.