I have attached the screenshot of my repeater and image Advance Custom Fields.
I have uploaded threeimages for the repeater images block.
And Now, I am able to get those boats but cant view it on the screen. I open up my inspect element and I see the while loop executing and showing all three boats code.
My Code:
<?php
/*
Template Name: boatProduct
*/ ?>
<?php get_header(); ?>
<?php if( have_rows('boat_product_slider') ): while ( have_rows('boat_product_slider') ) : the_row(); ?>
<div class="product_boat" style="background: url('<?php the_sub_field('slider_image'); ?>'); background-size: cover;">
</div>
<?php endwhile; endif; ?>
</div>
<div id="charter" class="brokerage" style="background: linear-gradient(rgba(255,255,255,0.95), rgba(255,255,255,0.95)), url('<?php the_field('agys_icon'); ?>') no-repeat center 48%; background-size: 80%; background-attachment: fixed;">
<h3 style="margin-top:40px;">Specification</h3>
<p align="justify"><?php the_field('content'); ?></p>
</div>
<?php get_footer(); ?>
There’s a slight change you need to make to your code, replacing
the_sub_field()
withget_sub_field()
.From the
get_sub_field()
documentation:The
the_sub_field()
function will print the results. This will not work for you as you’ve set yourslider_image
to return the “Image Object”.From the documentation:
Edit: “The Loop”
You have two options on how to handle the WordPress loop:
Option 1
The ACF functions need to be used inside the WordPress loop. For example (using
page.php
from the default TwentySixteen WordPress theme:Option 2
Alternatively, you can add the
$post_id
parameter tohave_rows()
to specify which post/page that the ACF fields should come from: