How to Get ACF Repeater Field Values in WordPress (With get_field() and have_rows() Examples)

Advanced Custom Fields (ACF) is one of the most powerful plugins in WordPress. Among its many features, Repeater fields allow you to add multiple sets of subfields dynamically. In this guide, we’ll show you how to correctly loop through Repeater fields using both get_field() and have_rows(), and explain when to use which method.

✅ Method 1: Using have_rows() and the_row()

This is the recommended method when dealing with Repeater fields, especially when rendering output directly in template files.

<?php if( have_rows('social_list', 'option') ): ?>
    <ul class="header-v2-social">
    <?php while( have_rows('social_list', 'option') ): the_row();
      $name = get_sub_field('social_name');
      $link = get_sub_field('links');
      $icon = get_sub_field('font_awesome_icon');
    ?>
      <li>
        <a href="<?php echo esc_url($link); ?>" title="<?php echo esc_attr($name); ?>">
          <i class="fa fa-<?php echo esc_attr($icon); ?>"></i>
        </a>
      </li>
    <?php endwhile; ?>
    </ul>
<?php endif; ?>

💡 When to Use:

  • Use this method when you’re inside a WordPress template file.
  • Best for direct HTML rendering with PHP loops.

✅ Method 2: Using get_field() (Returns an Array)

If you want to work with the data first or need to manipulate it before displaying, you can use get_field() which returns an array of rows:

<?php 
$social_list = get_field('social_list', 'option');
if( $social_list ): ?>
  <ul class="header-v2-social">
  <?php foreach( $social_list as $row ):
    $name = $row['social_name'];
    $link = $row['links'];
    $icon = $row['font_awesome_icon'];
  ?>
    <li>
      <a href="<?php echo esc_url($link); ?>" title="<?php echo esc_attr($name); ?>">
        <i class="fa fa-<?php echo esc_attr($icon); ?>"></i>
      </a>
    </li>
  <?php endforeach; ?>
  </ul>
<?php endif; ?>

💡 When to Use:

  • When you need to pre-process or filter data before output.
  • Great for use in plugins or backend logic.

📌 Notes:

  • Always sanitize output using esc_url(), esc_attr(), etc.
  • Use ‘option’ as the second parameter when pulling data from the Options page.
  • Make sure your ACF Pro license is active and the Repeater field is available.

🔄 How to Display the Above Code as Plain Code (Safe for Viewers)

To show the code to your site visitors without executing it, wrap it in a <pre><code> block like this:

<pre><code>
<?php if( have_rows('social_list', 'option') ): ?>
  <ul class="header-v2-social">
  <?php while( have_rows('social_list', 'option') ): the_row(); ?>
    <li>...</li>
  <?php endwhile; ?>
  </ul>
<?php endif; ?>
</code></pre>

🔍 Common Troubleshooting

  • Repeater not displaying? Make sure:
    • Field has data saved.
    • ACF group is assigned to the correct post/page.
    • You are using the right context (‘option’ for options page).

📚 Conclusion

Both have_rows() and get_field() are effective methods to loop through Repeater fields in ACF. Use have_rows() for direct output in templates and get_field() for processing the data beforehand. Following best practices will ensure clean, maintainable, and secure code on your WordPress site.