Support

Account

Home Forums General Issues Nested Repeater Showing Just One Value

Solved

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 endwhileand endiflines 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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.