Home › Forums › General Issues › 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';
}
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.