Home › Forums › Add-ons › Repeater Field › Filter Repeater row by Date Field › Reply To: Filter Repeater row by Date Field
Hi!
If each post had it’s own date field not in a repeater it’d been easier.. but as it is I suppose you’ll have to do something like this:
<?php if(get_field('matches')):
$i = 0;
$today = date('Y-m-d'); //This has to match the format of your date field
?>
<ul class="matches_list">
<?php while(has_sub_field('matches')): ?>
<?php if(strtotime($today) <= strtotime(get_sub_field('date'))){ ?>
<?php if($i < 5){ ?>
<?php $i++; ?>
<li class="match">
Hove (<?php the_sub_field('teams'); ?>) <strong><?php the_sub_field('hove_score'); ?> <span style="color: #A2224C; font-weight: bold;">-</span> <?php the_sub_field('opponent_score'); ?></strong> <?php the_sub_field('opponent'); ?><br><?php the_sub_field('date'); ?> @ <?php the_sub_field('location'); ?>
</li>
<?php } ?>
<?php } ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
This will not check to make sure the five chosen are the latest ones and it’s possible that due to the repeaterfield arrays setup you will end up with the five oldest ones (which have a date later or equal to today). If so you’ll have to first get the repeaterfield into a variable and do an array_reverse() on it!
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.