Support

Account

Home Forums General Issues Repeater Loop if else problem

Solved

Repeater Loop if else problem

  • Hey Guys,

    I have a function here that finds a repeater for a specific page and loops to find all fixtures that are ‘live’ (true). However, it’s returning ‘No Matches’ for all the fixtures that are not live – the ‘No Matches’ should represent all fixtures that are ‘not live’ (false) and show only once. Currently it shows ‘No Matches’ for all fixtures where ‘live’ is set to false.

    Could somebody help?

    function live_match($id) {
    
    	if( have_rows('fixtures', $id) ): 
    
    		while( have_rows('fixtures', $id) ): the_row(); 
    
    			$home 	= get_sub_field('home');
    			$away 	= get_sub_field('away');
    			$date 	= get_sub_field('date-time');
    			$video 	= get_sub_field('video');
    			$live 	= get_sub_field('live');
    
    			if ($live) : 
    
    				echo "<strong><a href='" . get_the_permalink( $id ) . "'>" . get_the_title( $id ) . "</a></strong>";
    				echo "<div class='match mt-15'>";
    				echo "<div class='row'>";
    				echo "<div class='col-md-4'><img src='" . get_template_directory_uri() . "/img/" . $home . ".jpg' /></div>";			
    				echo "<div class='col-md-4'><h2 class='mb-5'>VS</h2><span>" . $date . "</span><span>Venue</span></div>";
    				echo "<div class='col-md-4'><img src='" . get_template_directory_uri() . "/img/" . $away . ".jpg' /></div>";
    				echo "</div>";
    				echo "</div>";
    
    			else :
    
    				echo 'No Match'; 
    
    			endif;
    
    		endwhile;
    
    	endif;
    
    }

    Cheers

  • 
    function live_match($id) {
     
    		
    	$live_count = 0;
    
    	if( have_rows('fixtures', $id) ):
    		while( have_rows('fixtures', $id) ): the_row(); 
    
    			$home 	= get_sub_field('home');
    			$away 	= get_sub_field('away');
    			$date 	= get_sub_field('date-time');
    			$video 	= get_sub_field('video');
    			$live 	= get_sub_field('live');
    
    			if ($live) : 
    			
    				$live_count++;
    
    				echo "<strong><a href='" . get_the_permalink( $id ) . "'>" . get_the_title( $id ) . "</a></strong>";
    				echo "<div class='match mt-15'>";
    				echo "<div class='row'>";
    				echo "<div class='col-md-4'><img src='" . get_template_directory_uri() . "/img/" . $home . ".jpg' /></div>";			
    				echo "<div class='col-md-4'><h2 class='mb-5'>VS</h2><span>" . $date . "</span><span>Venue</span></div>";
    				echo "<div class='col-md-4'><img src='" . get_template_directory_uri() . "/img/" . $away . ".jpg' /></div>";
    				echo "</div>";
    				echo "</div>";
    
    			endif;
    
    		endwhile;
    
    	endif;
    	
    	if (!$live_count) {
    		echo 'No Match'; 
    	}
    
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Repeater Loop if else problem’ is closed to new replies.