Home › Forums › ACF PRO › if (have_rows()) not working › Reply To: if (have_rows()) not working
@swennet So I’m not sure if it’s a typo, but when retrieving a value from an options page, you use ‘option’ (singular), not ‘options’ (plural).
Also, the if statement will only return true or false. You need to loop through them and load the row’s data (the_row();) per loop iteration.
So your code would look something similar to:
<?php if ( have_rows('my_repeater', 'option') ) : ?> <ul> <?php //Use while loop to loop through rows, the_row() will load the row's data while( have_rows('my_repeater', 'option') ) : the_row(); // create variables for sub field values $sub_field = get_sub_field('sub_field'); ?> <li><?php echo $sub_field; ?></li> <?php endwhile; ?> </ul> <?php endif; ?>
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.