Support

Account

Home Forums Front-end Issues Nested Repeater Variable Only Returning Only One URL

Solving

Nested Repeater Variable Only Returning Only One URL

  • I’m using nester repeaters to allow admin users to upload up to 5 audio files and then display the URLs in HTML5 audio controls. It’s all working correctly except when you upload more than one file, only the first upload gets returned by the variable I’ve declared. The setup recognizes the correct amount of files uploaded and displays the correct numbers of rows (equal to the number of files uploaded), but the URL returned is only the first one uploaded. Here is the URL: http://bottomlineblack.com/voice-talent/

    And I’m referring to the Audio Samples section.

    Here is my code:

    			<?php if( have_rows('voice_talent_member') ): ?>
    
    			<ul class="slides">
    
    			<?php while( have_rows('voice_talent_member') ): the_row(); 
    
    				// vars
    				$name = get_sub_field('name');
    				$phone = get_sub_field('phone');
    				$email = get_sub_field('email');
    				$availability = get_sub_field('availability');
    				$access = get_sub_field('access_to_studio');
    				$turnaround = get_sub_field('turnaround_time');
    				$rates = get_sub_field('rates');
    				$access = get_sub_field('access_to_studio'); ?>
    
    				<?php if( have_rows('audio_samples_parent') ): ?>
    					<?php while( have_rows('audio_samples_parent') ): the_row();
    						$tracks = get_sub_field('audio_tracks'); ?>
    					<?php endwhile; ?>
    				<?php endif; ?>
    
    			?>
    
    				<li class="slide">
    
    					<h2><?php echo $name; ?></h1>
    					<div class="clear">
    					<div class="talenthalf"><strong><u>Phone</u><br /><?php echo $phone; ?></strong></div>
    					<div class="talenthalf"><strong><u>Email</u><br /><?php echo $email; ?></strong></div>
    					</div>
    					<div class="clear">
    					<div class="talenthalf"><strong><u>Availability</u><br /><?php echo $availability; ?></strong></div>
    					<div class="talenthalf"><strong><u>Access to Studio</u><br /><?php echo $access; ?></strong></div>
    					</div>
    					<div class="clear">
    					<div class="talenthalf"><strong><u>Turnaround Time</u><br /><?php echo $turnaround; ?></strong></div>
    					<div class="talenthalf"><strong><u>Rates</u><br /><?php echo $rates; ?></strong></div>
    					</div>
    					<div class="clear">
    					<div class="talenthalf"><strong><u>Acess To Studio</u><br /><?php echo $access; ?></strong></div>
    					<div class="talenthalf"><strong><u>Audio Samples</u><br />
    							<?php 
    							if( have_rows('audio_samples_parent') ): ?>
    								<ul>
    								<?php 
    
    								while( have_rows('audio_samples_parent') ): the_row();
    
    									?>
    									<li>
    										<audio controls>
      											<source src="<?php echo $tracks; ?>"  type="audio/mpeg">
    										</audio>
    									</li>
    
    								<?php endwhile; ?>
    								</ul>
    							<?php endif;
    							?>
    					</strong></div>
    					</div>
    
    				</li>
    
    			<?php endwhile; ?>
    
    			</ul>
    
    			<?php endif; ?>
  • Bump. Any help is appreciated guys; just figuring out how to store/echo multiple files within the $tracks variable. Thank you for your help!

  • Hi guys, got this figured out. Turns out rather than trying to define a “$tracks” variable, which can obviously only store one item, i left out the sub-repeater loop in the declaration area and simply used

    <div class="talenthalf"><strong><u>Audio Samples</u><br />
    							<?php 
    							if( have_rows('audio_samples_parent') ): ?>
    								<ul>
    								<?php 
    
    								while( have_rows('audio_samples_parent') ): the_row();
    
    									?>
    									<li>
    										<audio controls>
      											<source src="<?php the_sub_field('audio_tracks'); ?>"  type="audio/mpeg">
    										</audio>
    									</li>
    
    								<?php endwhile; ?>
    
    								</ul>
    							<?php endif;
    							?>
    					</strong></div>

    to loop through the files uploads. Hope this helps someone else!

  • Sorry, I have just joined the forums but I’ve noticed the same error with the first look I threw at your code.

    $tracks = "a simple variable";

    If you want to store tracks, then you should declare it as an array.

    
    $tracks = array();
    
    // now you should fill the array with data within your loop like this
    
    $tracks[] = "some value";
    

    Remember, when you want to retrieve values, you need to loop through the $tracks

  • Yes, an array is definitely what I was looking for. I knew i was close, just couldn’t put my finger on it. Thank you for the insight!

    Now, just to be clear then, the declaration portion of the code would look like:

    
    $tracks = array();
    
    <?php if( have_rows('audio_samples_parent') ): ?>
    	<?php while( have_rows('audio_samples_parent') ): the_row();
    		$tracks[] = get_sub_field('audio_tracks'); ?>
    	<?php endwhile; ?>
    <?php endif; ?>
    

    and then to loop through the values, i would then call:

    
    <?php 
    if( have_rows('audio_samples_parent') ): ?>
    	<ul>
    		<?php 
    
    		while( have_rows('audio_samples_parent') ): the_row();
    
    		?>
    			<li>
    										
                                <audio controls>
      											
                                 <source src="<?php echo $tracks; ?>"  type="audio/mpeg">
    										
                                </audio>
    			</li>
    
    		<?php endwhile; ?>
    
    	</ul>
    <?php endif; ?>
    

    Not sure if this is 100% right or not but any more info you can send my way is highly appreciated. Thanks!

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

The topic ‘Nested Repeater Variable Only Returning Only One URL’ is closed to new replies.