Home › Forums › General Issues › Loop through fields to find todays date › Reply To: Loop through fields to find todays date
For anyone who runs into this with same issue, this solution worked for me based on Johns response here… link
<?php
$found = false;
$value = date('l');
if( have_rows('opening_hour_settings', 'option') ) {
while( have_rows('opening_hour_settings', 'option')) {
the_row();
$storeopen = get_sub_field('open_message');
$storeclose = get_sub_field('closed_message');
while( have_rows('opening_hours')) { the_row();
if ($value == get_sub_field('day')) {
$found = true;
echo '<h5>' . $storeopen .'</h5>
<ul class="opentimes">';
//Loop through all opening times for that day
while( have_rows('times') ): the_row();
$open = get_sub_field('open_time');
$close = get_sub_field('close_time');
$times = '<li>' . $open . '-' . $close . '</li>';
echo $times;
endwhile;
echo '</ul>';
//break loop to just display first result
break;
}
}
}
// end while have rows
} // end if have rows
if (!$found) {
echo '<h5>' . $storeclose . '</h5>';
}
?>
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.