Home Forums Add-ons Repeater Field Repeaters/Lightboxes: Dynamically alternating variables Reply To: Repeaters/Lightboxes: Dynamically alternating variables

  • Hi @yulichka

    There are 2 ways to achieve the above.

    The 1st option is more efficient, but will require more code. This is to use an AJAX call to find the HTML instead of creating the inline content. You would need to create a PHP function in your function.php file and attach it to a WP AJAX action. You would then need to write some jQuery on the front end to post through the post_id, row_number and sub_field_name values for the PHP function to then load the flexibel content field and return the data needed.

    Your other option is to do what you already have but make some important changes.
    your code shows 2 issues:
    1. All your inline content is OUTSIDE the loop, so no data will load
    2. Your links and inline content id attributes do not contain a row identifier, so your javascript plugin won’t know which one to load.

    I think if you added a counter variable for the row number like so, it owuld all work:

    <?php if(get_field('media')): $i = 0; ?>
    		<?php while(has_sub_field('media')): $i++; ?>
    			<?php $file_type = get_sub_field('file_type'); ?>
    			<?php if( $file_type === 'audio' ) {?>
    					<a href="#audio-popup-<?php echo $i; ?>" class="popup">AUDIO</a>
    					<!-- INLINE LIGHTBOXES -->
    					<div id="audio-popup-<?php echo $i; ?>" class="audio popup-container mfp-hide">
    						<p class="title"><span>Audio Popup</span></p>
    						<?php the_sub_field('file'); ?>
    			<?php } ?>
    		<?php endwhile; ?>
    <?php endif; ?>

    Please note I have removed some code to clarify the solution