Support

Account

Home Forums Add-ons Repeater Field Hide repeated years in ACF with date picker

Helping

Hide repeated years in ACF with date picker

  • Hello,
    I’m having a repeater working as an events list with a date picker field to get the year of the event.

    I managed to sort them by date but, what I would like to achieve is that it only shows once the year 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 'No press yet!
    ';
                    endif; ?>
  • 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; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.