Support

Account

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

Solved

Repeater w/ 4 Groups, cannot get field values

  • I have a flexible content layout called Comparison Table, that holds a repeater of 4 Groups.
    The groups are ‘column1’, ‘column2’, ‘column3’ and ‘column4’.
    Each Group contains 3 fields, ‘type’, ‘image’ and ‘text’.

    I’m calling the layout correctly using:

    <?php elseif (get_row_layout() == 'comparison'): ?>
          <?php if(have_rows('comparison_rows')): ?>
    
    

    I’ve tried coding it like a nested repeater, which I read is what it acts like.. but, it doesn’t return any values.

    I’m trying to build a comparison table, with the 4 columns of data

    
    column1_type        column2_type        column3_type       column4_type
    column1_image       column2_image       column3_image      column4_image
    column1_text        column2_text        column3_text       column4_text
    

    Any suggestions??

  • I’ve tried looping through the groups with:

    
    	<?php if( have_rows('column1') ): ?>
    	    <?php while( have_rows('column1') ): the_row(); 
    	        the_sub_field('type');
    	        the_sub_field('image')['url'];
    	        the_sub_field('text');
    	        ?>
    	    <?php endwhile; ?>
    	<?php endif; ?>
    

    and

    
    	<?php $column1 = get_sub_field('column1'); ?>
    		
    	<?php if( $column1 ): ?>
    		<?php echo $column1['text']; ?>
    
    		// let's see if the value is in the sub_field()			
    	        <?php the_sub_field('type'); ?>
    	        <?php the_sub_field('image')['url']; ?>
    	        <?php the_sub_field('text'); ?>
    	<?php endif; ?>
    

    🙁

  • 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.

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

You must be logged in to reply to this topic.