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'); ?>
    				<?php } ?>
    			<?php } ?>
    		<?php endwhile; ?>
    <?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!