Home › Forums › Add-ons › Repeater Field › Nested Repeater w/ First Passing Variable to Second
Greetings. This is a nested repeater. The first repeater tells the second which ACF field to fetch and then is supposed to display its value in a table cell.
The first part works—all of the proper table headers are displayed in separate tables based on the first repeater—but the second part does not work. I’ve even tried to put random text (like “test”) in between the td
tags but nothing appears.
$fieldtofetch
is the variable in the first repeater that informs which ACF field to fetch in the second repeater (e.g., “part_number”).
Thanks for any help!
if ( have_rows( 'product_table' ) ) : ?>
<?php while (have_rows('product_table')):
the_row(); ?>
<table>
<h3><?php the_sub_field('product_table_title'); ?></h3>
<?php if (have_rows('product_table_columns')): ?>
<?php while (have_rows('product_table_columns')):
the_row(); ?>
<?php $tcols = get_sub_field('product_table_column'); ?>
<th><?php echo $tcols['label']; ?></th>
<?php $fieldtofetch = $tcols['value']; ?>
<?php if (have_rows('product_table_products')): ?>
<?php while (have_rows('product_table_products')):
the_row(); ?>
<?php $product_table_product = get_sub_field('product_table_product'); ?>
<?php if ($product_table_product): ?>
<tr><td><?php the_field($fieldtofetch); ?></td></tr>
<?php
endif; ?>
<?php
endwhile; ?>
<?php
endif; ?>
<?php
endwhile; ?>
</table>
<?php
endif; ?>
<?php
endwhile; ?>
<?php
endif; ?>
PS: I did try changing <?php the_field($fieldtofetch); ?>
to <?php the_sub_field($fieldtofetch); ?>
because I think that is correct but still no joy.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.