Support

Account

Home Forums Add-ons Repeater Field Repeater sorted by Date Reply To: Repeater sorted by Date

  • Oh wait this might be working…I am new to PHP….
    notice the instances of “$currMonth != $date->format(‘F’)”, I imagine this makes the function return a string, is that right?

    <?php
                 
                 $repeater = get_field('race_event');
                 foreach( $repeater as $key => $row )
                   { 
                     $column_id[ $key ] = $row['race_date'];
                   } 
                   array_multisort( $column_id, SORT_ASC, $repeater );
                   
                   $currMonth = "start";
                   foreach( $repeater as $row ) :
                   {
                     $date = DateTime::createFromFormat('Ymd', $row['race_date']); 
                     $website_url = $row['race_website'];
                     
                     if ($currMonth != $date->format('F')) :
                       {
                         echo '<h2>' . $date->format('F') . '</h2><br>';
                         $currMonth = $date->format('F');
                       }
                     endif;
                     
                     echo '<ul>';
    		               echo '<li><h2>' . $row['race_name'] . '</h2></li>';
    		               echo '<li>Date ' . $date->format('F d, Y') . '</li>';
    		               echo '<li>Distance ' . $row['race_distance'] . '</li>';
    		               echo '<li>Vertical ' . $row['race_vertical'] . '</li>';
    		               echo '<li>URL <a href=' . $website_url . '> ' . $website_url . ' </a></li>';
    		               echo '<li>' . $row['race_description'] . '</li>';
    		             echo '</ul>';
                   }
                   endforeach;
                   ?>