0
votes

I am trying to output an image from a repeater inside of a group in Advanced Custom Fields but I can't get the image URL. The group is called 'Homepage' and the repeater is called 'Slideshow' with a field of 'background_image'.

Please see below code.

    $rows = get_field('slideshow');

    if($rows) {
        $image = get_field('background_image');
        $size = 'full';

        foreach($rows as $row) {
?>
            <li class="swiper-slide">
                <div class="bg parallax2" data-speed='.5' style='background-image: url("<?php echo $image['url']; ?>")'></div>
            </li>
<?php
        }
    }
?>

The background-image URL is blank.

2

2 Answers

0
votes

This should work:

<?php
$homepageFields = get_field('homepage');

$slideshow = $homepageFields['slideshow'];

if ($slideshow) {
    $size = 'full';

    foreach ($slideshow as $row) {
        $image = $row['background_image'];
        ?>
        <li class="swiper-slide">
            <div class="bg parallax2" data-speed='.5' style='background-image: url("<?php echo $image['sizes'][$size]; ?>")'></div>
        </li>
        <?php
    }
}
?>
0
votes

Fields inside a repeater would be called subfields (get_sub_field), so you code should be

      $rows = get_sub_field('slideshow');

    if($rows) {
        $image = get_sub_field('background_image');
        $size = 'full';

        foreach($rows as $row) {
?>
            <li class="swiper-slide">
                <div class="bg parallax2" data-speed='.5' style='background-image: url("<?php echo $image['url']; ?>")'></div>
            </li>
<?php
        }
    }
?>