Support

Account

Home Forums Add-ons Repeater Field Loop Repeater Based on Sub Field Values Reply To: Loop Repeater Based on Sub Field Values

  • I need another piece of help related to this code snippet.

    I need to be able to add a header above this code snippet which has to be conditional based on having rows. I cannot have it in the ‘while’ section as the while loops through all the rows, not just the ones marked ‘functional assay.’

    For the time being I have done this:

    <?php
    if(have_rows('field_name')):
       while(have_rows('field_name')): the_row();
          if(get_sub_field('sub_field') == 'functional assay'):
             echo '<h4 class="underline">Functional Assay</h4>';
    break;
          endif;
       endwhile;
    endif;
    ?>
    
    <?php
    if(have_rows('field_name')):
       while(have_rows('field_name')): the_row();
          if(get_sub_field('sub_field') == 'functional assay'):
             the_sub_field('sub_field');
          endif;
       endwhile;
    endif;
    ?>

    I’m using the repeater loop twice, and the first instance is basically a check for rows, shows the title then breaks after the first row to not show the title multiple times.I feel this could be done in a much cleaner way, but I am not sure how.