Support

Account

Home Forums General Issues Nested repeater and true/false field

Solving

Nested repeater and true/false field

  • Hi,

    I’m trying to create a pricing table with four columns for three products. Instead of an html table, I’m using divs and list elements to make it easier for responsive.

    A list of features will be listed in the first column and the three columns to the right will contain a tick if the product contains the feature or will be blank if it doesn’t.

    I have created a Repeater field called ‘features’ containing a text field called ‘feature’ and three other repeater fields product_1, product_2 and product_3. Each of the nested repeater fields contain a True/False field called ‘included’

    I can get the first column of features to display no problem, but I can’t seem to get the true/false columns to work.

    <div class="one-fourth first">
    
    	<?php if ( have_rows('features', 11) ): ?> 
            
            	<ul>
                
    				<?php while ( have_rows('features', 11) ): the_row(); ?>
                        
                        	<li><?php the_sub_field('feature'); ?></li>
                            
                     <?php endwhile; ?>
                                
                 </ul>
         <?php endif; ?>  
    </div>
    
    <div class="one-fourth">
                        
    	<?php if( have_rows('product_1', 11) ): ?>
                            
    		<ul>
    
    			<?php while ( have_rows('product_1', 11) ): the_row(); ?>
                                    	
    				<?php if ( 'yes' == the_sub_field('included') ): ?>
        								
    					<li><span class="dashicons dashicons-yes"></span></li>
    							
    						<?php else: ?>
       		
    							<li></li>
    									
    				<?php endif; ?>      
                                    
                	<?php endwhile; ?>	
                  
              
             </ul>
                                  
         <?php endif; ?>
                                  
    </div>
  • Can you provide more information about the field setup? Your description is a little confusing. Maybe you can provide an image that shows the ACF field group or attach an export of the field group.

  • Hi – thanks for your reply.

    I’ve attached a screenshot of how the table looks in the admin area. As it’s a repeater, more rows can be added as required.

    See attached screenshot. I’ve also included the field export.

    Many thanks

    Brad

  • After looking at this I have another question or two.

    In the code you originally posted what does 11 represent
    if ( have_rows('features', 11) ):

    Using just html, without using any loops, can you code what you’d like it to look like? I’m not sure I understand from the description.

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

The topic ‘Nested repeater and true/false field’ is closed to new replies.