Home Forums Add-ons Repeater Field Repeater usage in version 4.x.x


Repeater usage in version 4.x.x

  • Hi,

    I am trying to use Repeater in ACF version 4.3.2. At this moment i need to stay in this old version. I have used ACF before, not extensively, and not lately.

    I could just use a snippet for the right syntax for displaying a Repeater on the page. I have looked for examples throughout the site, which is I am doing some small updates for, and they already have ACF as a plugin and ACF imported into the theme. ACF is in the dashboard GUI (version 4.4.12) as well as in non-GUI JSON (4.3.2). So it’s a bit confusing finding the right usage. I added the field via the GUI.

    Here are two snippets i tried neither of which displayed anything on the page.

    // example 1
    <?php if( get_field('product_categories') ): ?>
        <?php while( get_field('product_categories') ): the_row(); ?>
            <li>sub_field_1 = <?php get_sub_field('name'); ?>, sub_field_2 = <?php get_sub_field('icon'); ?>, etc</li>
            $sub_field_3 = get_sub_field('link'); 
            // do something with $sub_field_3
        <?php endwhile; ?>
    <?php endif; ?>
    // example 2
    <? if( have_rows('product_categories') ):
        while ( have_rows('product_categories') ) : the_row(); ?>
    <p><?php the_sub_field('name'); ?><p>
    <p><?php the_sub_field('icon'); ?><p>
    <p><?php the_sub_field('link'); ?><p>
        <? endwhile;
    endif; ?>

    Attached is a screenshot of my field in case it is needed:

    Any tips on my syntax?

    Thanks in advance!

  • Thanks @john i really appreciate that!

    I am still having trouble getting it to work. I first tried a few of the code examples from that link:

                $rows = get_field('product_categories_icons');
                    echo '<ul>';
                    foreach($rows as $row)
                    echo '<li>sub_field_1 = ' . $row['name'] . ', sub_field_2 = ' . $row['link'] .', etc</li>';
                    echo '</ul>';
                <?php if(get_field('product_categories_icons')): ?>
                    <?php while(has_sub_field('product_categories_icons')): ?>
                        <li>sub_field_1 = <?php the_sub_field('name'); ?>, sub_field_2 = <?php the_sub_field('icon'); ?>, etc</li>
                    <?php endwhile; ?>
                <?php endif; ?>

    Neither of which shows anything on the page. The site is on WPE and i have been clearing the cache with every try.

    Also i do not at the moment have access to the database which would be helpful for me just to confirm what’s coming from where (since ACF is implemented in both places like i mentioned.)

    So i am looking at other pages’ ACF code and am trying to emulating that. I have added this new field i am trying to display to the acf-register-field-groups.php as there are fields that only exist there, not in the GUI ACF, that are working and on pages.

    I am spending hours on this which is crazy, but there’s still something i am not doing right or seeing.

    Lastly i tried this:

    <?php if(get_field('product_categories_icons')) : ?>
                    <?php echo '<h1>true</h1>'; ?> 
                    <?php while(has_sub_field('product_categories_icons')): ?>
                        <li>icon = <?php echo get_sub_field('icon'); ?>
                        name = <?php echo get_sub_field('name'); ?></li>
                        <li>icon = <?php echo the_field('icon'); ?>
                        name = <?php echo the_field('name'); ?></li> 
                        <li>name = <?php echo the_sub_field('name'); ?>
                        icon = <?php echo the_sub_field('icon'); ?></li>
                    <?php endwhile; ?>
       <?php endif; ?>

    And since <?php echo '<h1>true</h1>'; ?> doesn’t print under the if something higher up is restricting this field’s display.

    If you have any ideas i’m all ears.


  • It has been an extremely long time since I’ve worked with ACF4. The only thing that I remember is that the function names used for repeater loops is different. I’m not even sure the documentation I found it the internet archive is the correct documentation. It could be that I found older or newer information than you need.

    More than likely, if this was me, I would download the plugin files for the repeater and I’d dig through that code to see how the code you have is actually working. Of find another repeater that is working and see how it is working.

  • Thank you John for the input – turn out, i needed to add 'options' after the field names in the PHP, so i figured it out. Thanks again!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.