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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.