1

I’m having a problem with the repeater field in Acf Pro. Basically, it works fine in the admin (it saves the data), but nothing shows up in the front. It's driving me mad because I'm using the exact same snippet in another website, same WP version, same ACF version, and it's working, but with the website I'm currently developing I'm having this problem both locally and in production.

The name of the repeater field is logo_grid It has an image field inside (URL type) named logo_grid_img

This is my code:

<?php if( have_rows('logo_grid_logos') ): ?>
    <?php while( have_rows('logo_grid_logos') ): the_row(); ?>
        <img src="<?php echo get_sub_field('logo_grid_img'); ?>">
    <?php endwhile; ?>
<?php endif; ?>

I tried var_dump and it just returns null.

<?php $my_var_dump =  get_field('logo_grid_logos'); ?>
<?php var_dump($my_var_dump); ?>

I’m quite desperate. Does anyone have any clues?

closed as off-topic by Howdy_McGee, Mayeenul Islam, fuxia May 17 '15 at 12:55

This question appears to be off-topic. The users who voted to close gave these specific reasons:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you post the context of your snippet? i.e. the code surrounding it. – TheDeadMedic May 15 '15 at 10:54
  • Hello! Actually I've just solved this issue, I had a query just before the custom fields and it had to be reset. I'll posting the answer with the working snippet. – mvicidomini May 15 '15 at 14:38
3

I've just solved this issue thanks to the Avanced Wordpress group in Facebook (https://www.facebook.com/groups/advancedwp/). It was actually a mistake I had made: I had a query before the custom fields and it had to be reset. This is the working snippet:

<?php
    // WP_Query arguments
    $args = array (
        'post_type'              => 'post',
        'posts_per_page'         => '4',
    );

    // The Query
    $query = new WP_Query( $args );

    // The Loop
    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            $query->the_post();
            the_title();
        }
    } else {
        echo 'No posts found';
    }

    // Restore original Post Data: this line was missing in my original code; adding it solved the issue.
    wp_reset_postdata();
?>

<?php if( have_rows('logo_grid_logos') ): ?>
    <?php while( have_rows('logo_grid_logos') ): the_row(); ?>
        <img src="<?php echo get_sub_field('logo_grid_img'); ?>">
    <?php endwhile; ?>
<?php endif; ?>

My original query is a little more complex but this is a working example. Thanks!

Not the answer you're looking for? Browse other questions tagged or ask your own question.