Support

Account

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>';
      }
    ?>