Support

Account

Home Forums Add-ons Repeater Field A repeater in random order including select fields Reply To: A repeater in random order including select fields

  • This should work. Put it in a list for now, will have to change that.

    <?php
     
    $rows = get_field('slider_image' );
    $sub_field = has_sub_field('slider_image');
    $rand_row = $rows[ array_rand( $rows ) ];
    $logo_colour = get_sub_field('logo_colour');
    $caption = get_sub_field('the_caption');
    $template_directory = bloginfo('template_directory');
    
    if($rows) // if slider_image exits
    	{
          echo '<h3>Header</h3>';
          echo '<ul>';
    
    		while($sub_field) // enables us to use get_sub_field
    		    {
    		    	
    		    	$rows = $rand_row; // random order of rows
    
    				foreach ($rows as $row) {
    
    					echo '<li>' . $caption . '</li>'; // displays caption
    
    					if(($logo_colour) == "white")) { // displays white logo if selected, else grey
    
    						echo '<li><img src="'. $template_directory . '/logo_white.png" /></li>';
    
    					} else {
    						
    						echo '<li><img src="'. $template_directory . '/logo_grey.png" /></li>';
    
    					}
    
    				} 
    	      	        
    	   echo '</ul>';
    	}
                 
    ?>