Support

Account

Home Forums Front-end Issues Looping through based on subfield values

Unread

Looping through based on subfield values

  • I’m trying to create tabs with content and that content will have different layouts based on a value in a checkbox field called ‘extras’ in my subfields. I’m new to ACF and not sure the best way to tackle this. I have a screenshot of the way my ACF’s are created.

    Parent Field

    Parent Field View

    Extra Subfield View

    Here is my code:

    <div class="tab-content random-number active">
              <?php
    
                if( have_rows('tab_content') ):
    
                  $posts = get_posts(array(
                    'numberposts' => -1,
                    'post_type' => 'tab_content',
                    'meta_key' => 'extras',
                    'meta_value' => 'center_rule'
                  ));
    
              while( have_rows('tab_content') ): the_row();
    
                if( have_rows('extras') ):
    
                  while( have_rows('extras') ): the_row(); ?>
                    <div class="center_rule">
                      <div class="row">
                        <div class="twelve columns">
                          <h1><?php echo the_sub_field('title'); ?></h1>
                        </div>
                      </div>
                      <div class="row">
                        <div class="six columns left-col">
                          <?php echo the_sub_field('column-1'); ?>
                        </div>
                        <div class="six columns right-col">
                          <?php echo the_sub_field('column-2'); ?>
                        </div>
                      </div>
                    </div>
                  <?php endwhile; ?>
    
                <?php endif; ?>
    
              <?php endwhile; ?>
    
              <?php endif; ?>
Viewing 1 post (of 1 total)

The topic ‘Looping through based on subfield values’ is closed to new replies.