Support

Account

Home Forums Add-ons Repeater Field How to get future events with Date Picker?

Solved

How to get future events with Date Picker?

  • I am trying to get all the events in the future.

    Now I have this:

    <?php if( have_rows(‘calender_event’, ‘option’) ): ?>
    <div class=”calender-table”>
    <table class=”table table-hover table-dark” style=”max-height: 100px; overflow-y: scroll;”>
    <thead>
    <tr>
    <th scope=”col”>Datum</th>
    <th scope=”col”>Evenement</th>
    <th scope=”col”>place</th>
    </tr>
    </thead>
    <tbody>
    <?php while( have_rows(‘calender_event’, ‘option’) ): the_row();

    // vars
    $name = get_sub_field(‘event_name’, ‘option’);
    $date = get_sub_field(‘event_date’, ‘option’);
    $place = get_sub_field(‘event_place’, ‘option’);

    ?>
    <tr>
    <td><?php echo $date; ?></td>
    <td><?php echo $name; ?></td>
    <td><?php echo $place; ?></td>
    </tr>
    <?php endwhile; ?>
    </tbody>
    </table>
    </div>
    <?php endif; ?>

    But this also shows the events in the past.

  • This is just a basic example, I could not copy and alter your code easily because you didn’t use code tags. You need to test the date before you output the table row, I can’t give specifics because that would depend on knowing how the date is being formatted. I am going to assume that dates are returned in the format “Y-m-d”, which would basically be the only way to tell if the date is in the future.

    
      if (have_rows('calender_event', 'option')) {
        while (have_rows('calender_event', 'option')) {
          $name = get_sub_field('event_name');
          $date = get_sub_field('event_date');
          $place = get_sub_field('event_place');
          $now = date('Y-m-d');
          if ($date > $today) {
            ?>
              <tr>
                <td>...</td>
                <td>...</td>
                <td>...</td>
              </tr>
            <?php 
          }
        } // end while have rows
      } // end if have rows
    
  • Wow, this is really simple thanks!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.