Support

Account

Home Forums Add-ons Repeater Field Date picker excluding past repeater fields

Solved

Date picker excluding past repeater fields

  • Hi, hope someone can help on this.

    I’m using a date picker in a repeater to show events and want to not show events that are before the current date.

    I’ve got the date to show by using the CreateFromFormat within the repeater, but need to figure out an if statement that excludes past entries.

    Everything I’ve found refers to excluding dates from a post loop and not in a repeater, so a little stumped. This is my code for showing the date.

    <?php if( have_rows('academy_dates') ): ?>
    			<?php while( have_rows('academy_dates') ): the_row();
    
    				// vars
    
    				$datetime = DateTime::createFromFormat('j F, y',           get_sub_field('date'));
    				$date_day = $datetime->format('j');
    				$date_month = $datetime->format('F');
    				$date_year = $datetime->format('y');
    				$month = get_sub_field('month');
    				$location = get_sub_field('location');
    				$title = get_sub_field('title');
    				$content = get_sub_field('academy_description');
    
    				?>
    
    				<div class="academy-date">
    					<div class="academy-date-inner">
    						<div class="date"><?php echo $date_day; ?></div>
    						<div class="month"><?php echo $date_month; ?> '<?php echo $date_year; ?></div>
    						<div class="divider-line"></div>
    						<div class="academy-title"><?php echo $title; ?></div>
    						<div class="location"><i class="fas fa-map-marker-alt"></i> <?php echo $location; ?></div>
    						<div class="description"><?php echo $content; ?></div>
    					</div>
    				</div>
    
    			<?php endwhile; ?>
    		<?php endif; ?>

    Hope someone can help.

    Thanks
    Aaron

  • Is this a date or a date/time field?

    
    // date field
    if (have_rows('academy_dates')) {
      while (have_rows('academy_dates')) {
       the_row();
       $raw_date = get_sub_field('date', false);
       $today = date('Ymd');
       if ($raw_date < $today) {
         // skip it
         continue;
       }
       // the rest of your code here....
      } // end while
    } // end if
    
    
    // time field
    if (have_rows('academy_dates')) {
      while (have_rows('academy_dates')) {
       the_row();
       $raw_date = date('Ymd', get_sub_field('date', false);)
       $today = date('Ymd');
       if ($raw_date < $today) {
         // skip it
         continue;
       }
       // the rest of your code here....
      } // end while
    } // end if
    
  • Hi John.

    It’s a date picker.

    Thanks for the example, will give it a go now!

    Thank you.
    Aaron

  • I forgot some semi-colons and edited

  • Thank you John, it worked perfectly!!

    Have a fantastic weekend.

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

You must be logged in to reply to this topic.