0

I'm using ACF plugin on my site. I want to sort my link containing date. So, in frontend I have something like that

01.10.2017, News
02.02.2018, News
06.09.2017, News

and I want it to be like that

02.02.2018, News
01.10.2017, News
06.09.2017, News

My code looks like this

<?php

$repeater = get_field('media');
$order = array();

foreach($repeater as $i => $row) {
    $order[$i] = $row['media_date'];
}

array_multisort($order, SORT_ASC, $repeater);

if($repeater): ?>

<ol>
    <?php foreach($repeater as $i => $row): ?>
        <li>
        <?php echo $row['media_date']; ?>, <a href="<?php echo 
$row['media_link']; ?>" target="_blank"><?php echo $row['media_title']; ?>
</a>
        </li>
<?php endforeach; ?>
</ol>
<?php else: 
    echo '<p>No matching post!</p>';
endif; ?>

And it sort data but incorrect. Incorrect I mean like this

01.10.2017, News
02.02.2018, News
06.09.2017, News

What I'm missing? How to order li items by date?

MMPL1
  • 533
  • 7
  • 21

0 Answers0