user1617218
user1617218

Reputation:

Display repeater field of ACF

i´m trying to display a repeater field made of images in my wordpress template but it just doesn´t work. I tried reading the doc of the plugin: http://www.advancedcustomfields.com/add-ons/repeater-field/ But still can´t make it work.

Here it´s the markup:

<div id="slideshow">
    <ul id="slides">
        <li><img src="<?php the_repeater_field('home_slider'); ?>" alt="" /></li>
    </ul>
</div>

The name of the repeater field is "home_slider" and the name of the field is "home_image". Please can someone help me out?

This is what displays after load the page:

<img src alt>

Upvotes: 2

Views: 6172

Answers (1)

ninja
ninja

Reputation: 2263

The repeater-field stores everything in a array, so you need to retreive it then loop it out, try this:

$slides = get_field('home_slider');  // Grabs the array

// Check if there is any data in the array before looping
if($slides) {
     echo '<ul id="slideshow">';
     foreach($slides as $s) {
         echo '<li>';
         echo '<img src="'.$s['home_image'].'" alt="" />';
         echo '</li>';
     }
     echo '</ul>';
}

Now depending on what you set the image to return (image url, attachement ID or Image Object ) you will need to use different methods to get the path to the image.

Upvotes: 6

Related Questions