Home Forums Add-ons Repeater Field Get only next date of repeater fields


Get only next date of repeater fields

  • I am using a repeater field to add various dates to one post.

    In each repeater there are stored three variables:

    si-date, si-time, si-special

    Currently I am using the si-date field like so:

    $dateformatstring = "d.m. l,";
    $unixtimestamp = strtotime(get_sub_field('si-date'));
    echo date_i18n($dateformatstring, $unixtimestamp); 

    I have got two questions I am not able to do on my own:

    – How can I display only the repeater row containing the next upcoming date (or todays date)
    – How can I display a custom message if all dates have passed by?

  • Hi @marianrick

    I believe you can do it like this:

    // check if the repeater field has rows of data
    if( have_rows('repeater_field_name') ):
        $have_date = false
        $today = date('Ymd');
     	// loop through the rows of data
        while ( have_rows('repeater_field_name') ) : the_row();
            $thedate = get_sub_field('si-date', false);
            if($thedate > $today){
                $have_date = true;
                $dateformatstring = "d.m. l,";
                $unixtimestamp = strtotime($thedate);
                echo date_i18n($dateformatstring, $unixtimestamp); 
            echo "no dates";
    else :
        // no rows found

    I hope this helps.

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

The topic ‘Get only next date of repeater fields’ is closed to new replies.