Home Forums Add-ons Repeater Field Slider repeater – Show within start and end date


Slider repeater – Show within start and end date

  • Hi!

    I’m in the process of making a top slider with the help of a repeater field. I’m facing an issue however.. While the slider works just fine on its own, i want to make a function which makes me able to set a start date and an end date for each individual row. While the current date is within the start date and end date, the slider should be visible on the frontend. This is my current code. I’ve made two subfields (date picker) within the repeater field (start_date) and (end_date). Looking through other posts within the matter, i have tried to make it work, but without succes.

    I’m still fairly new to ACF so excuse me if the code seems silly/redundant. Any help would really be appriciated!!

        $rows = get_field('slides');
        if( $rows ) {
            echo '<div class="slider-my-page">';
            $today = date('Ymd');
            $start_date = get_sub_field('start_date');
            $end_date = get_sub_field('end_date');
            foreach( $rows as $row ) {
              // if ((strtotime($today) >= strtotime($start_date)) && (strtotime($today) <= strtotime($end_date))) {
                $image = $row['image'];
                $tekst = $row['tekst'];
                echo '<div>';
                  echo wp_get_attachment_image( $image, 'full' );
                  echo '<div class="slides-wrap">';
                    echo $tekst;
                  echo '</div>';
                echo '</div>';
            echo '</div>';

  • ACF stores dates as ‘Ymd’ but this may not be how they are returned. See your field settings.

    strtotime() will not work with a date formatted as ‘Ymd’. Date functions require dates in one of the accepted formats

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

You must be logged in to reply to this topic.