Support

Account

Home Forums Add-ons Repeater Field Repeater not working in IF

Solved

Repeater not working in IF

  • If I remove the if statements, this works perfectly. However with the IF statement in, I only see the first row from the repeater. What am I doing wrong? (thanks in advance!)

    <?php if( have_rows('activity_links') ): the_row(); ?>
    <h3>Links</h3>
    <ul>
    <?php while( have_rows('activity_links') ): the_row(); ?>
    <li><a href="<?php echo the_sub_field('link_url'); ?>"><?php echo the_sub_field('name_for_link'); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>
  • You don’t need “the_row()” on the first line. The correct code would be:

    <?php if(have_rows('activity_links')): ?>
      <h3>Links</h3>
      <ul>
        <?php while(have_rows('activity_links')): the_row(); ?>
        <li><a href="<?php echo the_sub_field('link_url'); ?>"><?php echo the_sub_field('name_for_link'); ?></a></li>
        <?php endwhile; ?>
      </ul>
    <?php endif; ?>
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Repeater not working in IF’ is closed to new replies.