I am setting up a carousel using the Advanced Custom Fields (ACF) plugin. This carousel is being set up inside a flexible content.
I’ve created a “block_id” field in order for the user to assign an ID to that specific block that is being created. Inside of it, there is a repeater field in which image slides will be loaded.
The problem is that due to the nature of the carousel, I need to pass this “block_id” variable inside the repeater field. However, when doing this, I get a variable not defined since most likely the ACF repeater field will only read variables inside of it. Is there a way using PHP that I can pass this variable no matter if it’s outside the repeater loop?
Here is my current code:
<?php $block_id = get_sub_field('block_id'); ?> <section <?php block_id(); ?> class="hero carousel slide carousel-fade" data-ride="carousel" data-interval="7000" data-pause="false"> <!-- Start slides --> <?php if( have_rows('slide') ): ?> <ol class="carousel-indicators"> <?php while ( have_rows('slide') ) : the_row(); ?> <li data-target="#<?php echo $block_id; ?>" data-slide-to="<?=$indicatorCount?>" class="<?php echo ($indicatorCount==0) ? "active" : "" ?>"></li> <?php endwhile; ?> </ol> <!-- /.carousel-indicators --> <div class="carousel-inner"> <?php while ( have_rows('slide') ) : the_row(); ?> <div class="item"> </div> <?php endwhile;?> </div> <!-- .carousel-inner --> <?php endif; ?> <!-- End slides --> </section> <!-- section -->
Read more here: Retrieve value from a field outside a repeater loop