Support

Account

Home Forums Add-ons Repeater Field Get date value in strtotime only from last row of a reapeater

Unread

Get date value in strtotime only from last row of a reapeater

  • Hello,

    Here is a part of a template I have problem with.

    I query an event custom post type, that contain a date repeatear. I check each value from date to only display events that will occur in futur. The following loop will display “something” many time from the main event unfortunatly but only want it displayed once.

    if( $listing_post->have_posts() ){
    	$dateformat = "YmdHi";
    	$actualdate = current_time( $dateformat );
    	if( have_rows('event_openhours') ):
    		while (have_rows('event_openhours') ) : the_row();
    			$eventendate = strtotime(get_sub_field('event_date_end', false, false));
    			$eventendate = date_i18n($dateformat, $eventendate);
    			// eventdate is set
    			// if ending date is ≥ actual date we display post
    			if($actualdate < $eventendate) :
    				echo "something";
    			endif;
    		endwhile;
    	endif;
    endif;

    I found a kind of solution :

    
    $dateformat = "YmdHi";
    $actualdate = current_time( $dateformat );
    $repeater = get_field('event_openhours');
    $last_row = end($repeater);
    $eventendate = $last_row['event_date_end'];
    if($actualdate < $eventendate) :
    	echo "something";
    endif;
    

    Which could replace the if / while and only check value from last reapeater value, but the problem I get is $eventdate only return a text value from the date picker. How can I translate it to a “YmdHi” format ?
    Actually $actualdate and $eventdate are in different format.

    Thank you for your help.

Viewing 1 post (of 1 total)

The topic ‘Get date value in strtotime only from last row of a reapeater’ is closed to new replies.