Support

Account

Home Forums Add-ons Repeater Field Hide the title if the repeater's subfields are empty Reply To: Hide the title if the repeater's subfields are empty

  • If title is a sub field this should work. If it’s not a sub field, change it to get_field(‘title’)

    <?php
     if( have_rows('repeater_field_name') ):
      $title = get_sub_field('title');
      $repeater_subfield_name = get_sub_field('repeater_subfield_name');
       if( !empty($repeater_subfield_name) ):
    ?>
    <h2><?php echo $title ?></h2> // need to hide this if subfield is empty
    <?php endif; ?>
    <ul>
     <?php while ( have_rows('repeater_field_name') ) : the_row(); ?>
      <li><?php echo $repeater_subfield_name ?></li>
     <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    Hope it works. 🙂