Support

Account

Home Forums Add-ons Repeater Field Retrieve value from Repeater field and re-use outside of loop

Helping

Retrieve value from Repeater field and re-use outside of loop

  • Hey, folks,

    I am trying to retrieve a value from a repeater sub-field to re-use outside of my repeater loop. Basically, I have two UL’s. The first is a list of slides, which I am using a repeater for. The second, is a custom navigation of the slide.

    I was thinking that I might be able to save the field content as a variable, but I do not understand how I might be able to save the correct field data from a specific row in the repeater.

    This is my code as of now, the .nav-slide UL is where I want to re-use the data.

    <ul class="slides">
    	<?php if( have_rows('slideshow') ): while ( have_rows('slideshow') ) : the_row(); ?>
            <li class="<?php the_sub_field('color_scheme'); ?>">
            	<h4><?php the_sub_field('headline_1'); ?></h4>		
            </li>
    	<?php endwhile; else : endif; ?>
    </ul>
    
    <ul class="nav-slide">
        <li class="<?php the_sub_field('color_scheme'); ?>"><?php the_sub_field('headline_1'); ?></li>
    </ul>

    Any feedback/input would be greatly appreciated.

    Thanks!

  • I would suggest you to always first make:

    <pre>
    print_r( $field );
    </pre>

    I personally don’t use these functions, i use standard php foreach loop.
    Repeater field, especially when it’s nested returns very complex multidimensional array, so maybe first try to simplify your array.
    Or you can maybe try to access it like: field[0][tab1][value1][0]

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.