Support

Account

Home Forums Add-ons Repeater Field Repeater w/ 4 Groups, cannot get field values Reply To: Repeater w/ 4 Groups, cannot get field values

  • This is a solution for using GROUPS within a REPEATER. These are located in a Flexible Content field of Comparison – omit this IF statement if you’re not using within a Flexible Content field.

    Specifically, I have a REPEATER named ‘comparison_rows’ containing 4 Groups
    (The groups are named column_1, column_2, column_3 and column_4)

    This is so the user can create a comparison table, with the fields for each cell grouped together. Each cell contains an image, text and specific CSS class (which I use ‘type’ to change)

    Column_1 has these fields: text1, type1 and image1
    Column_2 has these fields: text2, type2 and image2
    and so on…

    The fields in each group are:
    text (text fields, go figure)
    type (select fields, with a list of classes, used to change classes on the elements)
    image (image fields returning the URL)

    Here’s is what worked:

    
    <?php elseif (get_row_layout() == 'comparison'): ?>
    	<?php if(have_rows('comparison_rows')): ?>
    		<?php while(have_rows('comparison_rows')): the_row(); ?>
    			<?php
    			$column_1 = get_sub_field('column_1'); // name of group 1
    			$column_2 = get_sub_field('column_2'); // name of group 2.. and so on			$column_3 = get_sub_field('column_3');
    			$column_4 = get_sub_field('column_4');
    			?>						
    				<div class="<?php echo $column_1['type1']; ?>">
    					<?php if ($column_1['image1'] ): ?>
    						<img src="<?php echo $column_1['image1']; ?>"  class="comparison-img"  />
    					<?php endif; ?>
    					<p><?php echo $column_1['text1']; ?></p>
    				</div>
    				
    				<div class="<?php echo $column_2['type2']; ?>">
    					<?php if ($column_2['image2'] ): ?>
    						<img src="<?php echo $column_2['image2']; ?>"  class="comparison-img" />
    					<?php endif; ?>
    					<p><?php echo $column_2['text2']; ?></p>
    				</div>
    				
    				<div class="<?php echo $column_3['type3']; ?>">
    					<?php if ($column_3['image3'] ): ?>
    						<img src="<?php echo $column_3['image3']; ?>"  class="comparison-img" />
    					<?php endif; ?>								
    					<p><?php echo $column_3['text3']; ?></p>
    				</div>
    				
    				<div class="<?php echo $column_4['type4']; ?>">
    					<?php if ($column_4['image4'] ): ?>
    						<img src="<?php echo $column_4['image4']; ?>"  class="comparison-img" />
    					<?php endif; ?>								
    					<p><?php echo $column_4['text4']; ?></p>
    				</div>
    					
    			<?php endwhile; ?> 
    	<?php endif; ?>
    <?php endif; ?>
    
    

    Maybe this will help someone down the road.