Support

Account

Home Forums ACF PRO Repeater Loop returns only first sub field value

Solved

Repeater Loop returns only first sub field value

  • I am using ACF Pro 5.1.3 and I have repeater field in an options page. Each repeater value has 3 sub fields. When I use the following code then only the first sub field returns value while the other 2 are empty:

    <div class="clientslider">
                    <?php
                    	if (have_rows('clients', 'option')):
    				?>
                        <ul>
                            <?php while (have_rows('clients', 'option')): ?>
                            	<?php
    								the_row();
    							?>
                                <li><a href="<?php the_sub_field('url'); ?>"><img src="<?php the_sub_field('logo'); ?>" alt="<?php the_sub_field('name'); ?>" width="160" height="80" /></a></li>
                            <?php endwhile; ?>
                        </ul>
                    <?php endif; ?>
                </div>

    If I use get_field(‘clients’, ‘option’); then I can see that the return array only contains the first sub field values.

    Is this is a known bug in ACF Pro or I am doing something wrong?

  • Hi @wesadaf

    Are you able to provide the returned data from the following code:

    
    <?php echo '<pre>';
    	print_r( get_field('clients', 'option') );
    echo '</pre>';
    ?>
    

    Can you also confirm that the repeater field settings include the correct sub field’s and re-save the field group.

    The issue sounds like ACF is having trouble loading the sub field values which is either an issue with the field’s settings, an issue with JSON file or an issue with the DB data.

    Thanks
    E

  • @Elliot, The dump would only return single field but I was able to fix the problem.

    The problem was due to the use of pre_get_posts action in the functions.php so I had to disable it to fix the problem.

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

The topic ‘Repeater Loop returns only first sub field value’ is closed to new replies.