I have nested repeater fields with Advanced Custom Fields, in my template I use if while loops to display them. The fields are category (the post) > subcategory > product. At the bottom level (product) I trigger a modal, in the header of this modal I want category_name > subcategory_name > product_name …the first one works fine because I simply use the post title (the_title) the last one also works because I am at that level and only have to call the_sub_field('product_name') but I don't know how to call the subcategory name value, I have tried the_sub_field('subcategory_name') and the_field('subcategory_name') both returning blank. Is there a way to pass the value from the parent loop to the child?
Here's what it looks like:
<?php if( have_rows('category') ): while ( have_rows('category') ) : the_row(); ?>
<h3><?php the_sub_field('category_name'); ?></h3>
<?php if( have_rows('product') ): while ( have_rows('product') ) : the_row(); ?>
<a href="#<?php the_sub_field('modal_id'); ?>" data-toggle="modal" >
<?php the_sub_field('product_name'); ?>
</a>
<!-- THE MODAL -->
<div id="<?php the_sub_field('modal_id'); ?>" class="modal fade" ...>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">
<?php the_title(); ?>
>
<?php the_sub_field('category_name'); ?><!-- DOESN'T WORK -->
>
<?php the_sub_field('product_name'); ?>
</h4>
</div>
<div class="modal-body">
Product details here
</div>
</div>
</div>
</div>
<?php endwhile; endif; ?>
<?php endwhile; endif; ?>