ACF Repeater Fields

Getting values from a repeater field in Advanced Custom Fields (ACF) is pretty straightforward. ACF repeater fields are super handy for creating sets of repeatable data, like a list of team members, event schedules, or image galleries. Here’s a basic rundown on how to fetch those values:

Assuming you have a repeater field set up in ACF called your_repeater_field and you want to get its values:

  1. Check if there are any rows to loop over: First, you use a conditional check to see if there’s any data to loop through. ACF provides a function have_rows() for this purpose.
  2. Loop through the rows: If there are rows available, you use a while loop combined with the_row() to iterate through them.
  3. Get sub field values: Inside the loop, you can fetch the values of the sub fields using the get_sub_field() function.

Here’s how the code typically looks:

if( have_rows('your_repeater_field') ): // 1. Check for rows
    while ( have_rows('your_repeater_field') ) : the_row(); // 2. Loop through rows

        // 3. Get sub field values
        $sub_value = get_sub_field('your_sub_field');

        // Now you can do something with each sub value
        echo $sub_value;

else :
    // No rows found

Just replace 'your_repeater_field' with the actual name of your repeater field, and 'your_sub_field' with the name of the sub field you want to fetch.

Remember, this is a basic example. Depending on your project, you might want to format the output differently, like wrapping items in HTML elements or building out a more complex structure. ACF is pretty flexible, so you can get pretty creative with how you display your data!