0
votes

I am trying to loop out a repeater field in my wordpress front-page template But for some reason the div is empty and doesn't seem to work. I am 100% sure my code is correct so there must be an issue. Anyone has any idea what it could be?

This is how my loop looks like, the field keys are correct! :)

<?php
/**
 * Template Name: Front Page Template
 */
?>

<?php while(have_posts()) : the_post(); ?> 
    <?php if( have_rows('achtergrond_afbeeldingen') ): ?>
        <div class="slider-circles">
                <?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
                    <p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"></p>
                <?php endwhile; ?>
        </div>
    <?php endif; ?>
<?php endwhile; ?> 

This is what my front-page.php looks like. The funny thing I've used this in an other project before and everything worked fine. Now my screen is just blank, I have no idea what's going on.

3
What could be the reason then that the loop doesn't work? I check my source code and the div is emptyFrank Lucas

3 Answers

0
votes

if have_rows('field_56e7d8bebb545') is really true, debug the_row();

var_dump(the_row());

You can view the_result, if is empty, maybe you must set a second parameter for have_row($field_name, $post_id)

0
votes

field_56e7d8bebb545 is the field key, not the field name. The field name must be used in the have_rows() function. This can be found on the Advanced Custom Fields screen next to the label -

enter image description here

0
votes

Try this one .. since you have not printed any such thing that can be displayed in browser .. you only provided the data attribute to div.

Write something inside inner HTML might see you repeater values

<?php
/**
 * Template Name: Front Page Template
 */
?>

<?php while(have_posts()) : the_post(); ?> 
    <?php if( have_rows('achtergrond_afbeeldingen') ): ?>
        <div class="slider-circles">
                <?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
                    <p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"><?php the_sub_field('image'); ?></p>
                <?php endwhile; ?>
        </div>
    <?php endif; ?>
<?php endwhile; ?>