Support

Account

Home Forums Add-ons Repeater Field Order Repeater Field Rows by Date

Solved

Order Repeater Field Rows by Date

  • Hi, I’m trying to order my repeater field rows by a datepicker subfield. This is what I have so far:

    
    $repeater = get_sub_field('fixture');
        foreach( $repeater as $key => $row ) { 
            $column_id[ $key ] = $row['date'];
    }
    
    array_multisort( $column_id, SORT_DESC, $repeater );
    
    foreach( $repeater as $row ) {
        // Stuff
    }

    It’s currently outputting the rows in this order:
    29/08/2015
    23/08/2015
    17/08/2015
    14/08/2015
    11/08/2015
    09/09/2015
    05/09/2015

    Whereas I need it to be in date order (most recent to least recent). It seems to almost be doing the right thing, but only taking into account the days and not the months.

    Can anyone suggest how to achieve this last step? Thanks!

  • Anyone? Some help with this would be greatly appreciated.

    Thank you

  • you need to set Return Format to Ymd because only then you can order dates correct.
    and use something like this:

    $get_startdate = get_field('my_startdate'); 
    $start_date = (strtotime($get_startdate));
    //use $get_startdate to order, and $start_date_pretty to output your date
     $start_date_pretty = date_i18n( 'd/m/Y', $start_date );
    echo $start_date_pretty;
    

    hope that help you to get what you wish to try

  • I just needed to change the Return Format for the date field to Ymd in the backend as suggested.

    Thanks so much for your help mediawerk.

    Can’t believe it was that simple!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Order Repeater Field Rows by Date’ is closed to new replies.