Home › Forums › Add-ons › Repeater Field › Hide repeated years in ACF with date picker › Reply To: Hide repeated years in ACF with date picker
Hello,
I’m having a repeater working as an events list.
I managed to sort them by date but, what I would like to achieve is that it only shows the year once if multiple events are happening in the same year.
Currently:
2020. Event 1
2020. Event 2
2020. Event 3
2019. Event 4
2018. Event 5
2017. Event 6
2017. Event 7
2016. Event 8
What I want:
2020. Event 1
Event 2
Event 3
2019. Event 4
2018. Event 5
2017. Event 6
Event 7
2016. Event 8
Is this possible?
I know that WordPress native date function shows it repeated years only once unless you echo them.
Here’s my code:
<?php
$repeater = get_field('press');
$order = array();
foreach ($repeater as $i => $row) {
$order[$i] = strtotime($row['date']);
}
array_multisort($order, SORT_DESC, $repeater);
if ($repeater): ?>
<ol style="list-style-type:none;">
<?php foreach ($repeater as $i => $row): ?>
<li>
<?php echo $row['date']; ?> <a href="<?php echo
$row['link']; ?>" target="_blank"><?php echo $row['article']; ?>
</a>
</li>
<?php endforeach; ?>
</ol>
<?php else:
echo '<p>No press yet!</p>';
endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.