Support

Account

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

  • Do you mind giving me any tips on formatting and code structure? I am kinda new to PHP and although this works I am not confident.

    One other question I have is, can you recommend a way to approach a UI that would let a user jump to points on the page that are grouped into the same month? Back story is each repeater will have a name and date and now, since I can sort the list by date I was hoping to make it easier for the user to jump to the content for August.

    <!-- repeater	-->
       <?php
         $repeater = get_field('race_event');
           foreach( $repeater as $key => $row )
             { 
               $column_id[ $key ] = $row['race_date'];
              } 
                array_multisort( $column_id, SORT_ASC, $repeater );
                foreach( $repeater as $row ) :
                  {
                    echo '<li>' . $row['race_name'] . '</li>';
    		$date = DateTime::createFromFormat('Ymd', $row['race_date']); 
    		echo '<li>' . $date->format('m-d-Y') . '</li>';
                   }
             endforeach;
         ?>          
    <!-- /repeater	-->