Home Forums Add-ons Repeater Field Show future dates using date & time, repeater fields


Show future dates using date & time, repeater fields

  • I’d like to only display future events. I’ve found a bunch of examples that are close but nothing that uses date & time field and the repeater fields. The events only have the one date, no ending date.

    Date output format is: F j, Y – g:i a
    Any help getting started would be so appreciated. Thank you!

    if( have_rows('dates_offered') ): while ( have_rows('dates_offered') ) : the_row(); 
      // variables
        $free = get_sub_field('event_payment_type');
        $soldout = get_sub_field('sold_out');
        $eventlink = get_sub_field('event_map_link');
        $eventloc = get_sub_field('event_location');
        $eventfb = get_sub_field('fb_event_link');
        $eventseries = get_sub_field('event_name_if_series');
    		$eventTIME = get_sub_field('event_date_time');
    <?php if( $soldout ){ ?>
    	<span class="eventROW soldout">
    <?php } else { ?>	
    	<span class="eventROW">
    <?php } ?>	
    				<?php if( $eventseries ): ?><span class="big"><em><?php the_sub_field('event_name_if_series'); ?></em></span><br /><?php endif; ?>
         		<?php if( $eventTIME ): ?>★ <strong><?php the_sub_field('event_date_time'); ?></strong> ★<?php endif; ?>
    		 		<?php if ($free == 1){ ?>
    		 				<?php if( $soldout ){ ?>	
    				 				<span class="full">FULL</span>
    				 		<?php } else { ?>
    				 				<a class="buynow" target="_blank" href="<?php the_sub_field('registration_link'); ?>">Register</a>
    				 		<?php } ?>	
    		 		<?php } else { ?>			 		
    				 		<?php if( $soldout ){ ?>	
    				 				<strike>$<?php the_sub_field('event_price'); ?></strike> <span class="full">FULL</span>
    				 		<?php } else { ?>
    				 				<span class="eventcost">$<?php the_sub_field('event_price'); ?></span>
    				 				<a class="buynow" target="_blank" href="<?php the_sub_field('event_purchase_link'); ?>">Buy Now</a>	
    				 		<?php } ?>		
    		 		<?php }?>
    		 		<?php if( $eventloc ): ?>	
    				 		<?php if( $eventlink ){ ?>	
    				 				<span class="eventlocation">@ <a target="_blank" href="<?php the_sub_field('event_map_link'); ?>"> <?php the_sub_field('event_location'); ?></a></span>
    				 		<?php } else { ?>
    				 				<span class="eventlocation">@ <?php the_sub_field('event_location'); ?>	</span>
    				 		<?php } ?>
    		 		<?php endif; ?>
    		 		<?php if( $eventfb ): ?>
    		 			<a class="fbRSVP" target="_blank" href="<?php the_sub_field('fb_event_link'); ?>"><i class="fa fa-facebook-official" aria-hidden="true"></i> RSVP on Facebook</a>
    		 		<?php endif; ?>
    	</span><!-- end eventROW -->		
      <?php endwhile; ?>
    <?php else :?>
    <h3>No dates available at this time.</h3>
    <?php endif; ?>
  • Solved! Thanks to James and a help ticket and this blog post:

    First I changed the date&time field output to a unix timestamp, to do so just put a capital U under custom.

    then add:

    $eventTIME = get_sub_field('event_date_time');
    $today = current_time('timestamp'); // Get current unix timestamp
    if($eventTIME<$today) continue; 

    If the event date is smaller than today’s date it skips it.

    However, all my pretty dates were now displaying as unix timestamps. I changed the code to display them to this:

    <?php $start = get_sub_field('event_date_time'); echo date_i18n('F j, Y - g:i a', $start); ?>

    And done!

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Show future dates using date & time, repeater fields’ is closed to new replies.