Home › Forums › General Issues › Nested Repeater Showing Just One Value
Greetings – I need the third repeater here (product_table_products
) to loop within the second repeater (product_table_columns
).
Right now, the second repeater is returning (via the $tcols
variable) only the very last field value because the second repeater loops until it’s done and then moves on to the next bit of code–the third repeater. I need this code to loop through the second and third repeaters as one.
I’ve tried moving the endwhile
and endif
lines all over the place in an attempt to make them loop together to no avail.
<?php 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 $product_table_column_selected_option = get_sub_field( 'product_table_column' ); ?>
<?php if ( $product_table_column_selected_option ) : ?>
<th><?php echo esc_html( $product_table_column_selected_option['label'] ); ?></th>
<?php $tcols = esc_html( $product_table_column_selected_option['value'] ); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?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 ) : ?>
<?php $tdata = get_field($tcols, $product_table_product->ID); ?>
<tr><td><?php echo $tdata ?></td></tr>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</table>
<?php endwhile; ?>
<?php endif; ?>
Is the repeater for product_table_products nested in the product_table_columns repeater or are both of the repeaters sub fields of product_table.
Sorry – I solved this last night and forgot to close it. I built an array first then looped through those with foreach.
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.