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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.