0
votes

I have been trying to order my ACF subfields by date order, however it isn't working quite right. It should go

01/06/2020 20/05/2020 14/05/2020 10/05/2020

but it currently goes

01/06/2020 10/05/2020 14/05/2020 20/05/2020

this is my code, can someone please tell me where I have gone wrong?

<section class="news-updates">
        <?php
    $repeater = get_field('news_repeater');
    $order = array();

    if( $repeater ):
        foreach( $repeater as $i => $row ) {

            $eventdate = $row['news_date'];
            $order[ $i ] = $eventdate;

        }
    array_multisort( $order, SORT_ASC, $repeater );
?>



        <table class="news">
            <?php foreach( $repeater as $i => $row ): ?>
            <?php
                $eventdate = $row['news_date'];
             ?>


            <div class="news-item">
                <div class="news-date"><?php echo $eventdate; ?></div>
                <div class="news-content"><?php echo $row['description']; ?></div>
            </div>


            <?php endforeach; ?>
        </table>
        <?php

?>
        <?php endif; ?>
    </section>

I have looked all over the internet but can't seem to figure it out.

1
“can someone please tell me where I have gone wrong?” - you are trying to sort dates in a format, that is not “sortable” to begin with. Sorting happens by doing a string comparison of two items here, character-by-character, from left to right.CBroe

1 Answers

0
votes

Did you tried

array_multisort( $order, SORT_ASC, $repeater );