Support

Account

Home Forums Add-ons Repeater Field How do I only show future events? Reply To: How do I only show future events?

  • Hey guys!

    I have the same issue, i want to display future post only.
    I tried the solution Jason typed out.

    Here is my code.

    `<?php

    //Set server timezone to central
    date_default_timezone_set(‘Europe/Amsterdam’);
    //Today’s date
    $date_1 = date(‘Ymd’, strtotime(“now”));
    //Future date – the arg will look between today’s date and this future date to see if the post fall within the 2 dates.
    $date_2 = date(‘Ymd’, strtotime(“+12 months”));

    ?>

    <?php
    //arg to determine if the post is an upcoming event.
    $upcoming_args = array(
    ‘post_type’ => ‘programma’,
    ‘posts_per_page’ => -1,
    ‘meta_key’ => ‘start_date’,
    ‘meta_compare’ => ‘BETWEEN’,
    ‘meta_type’ => ‘numeric’,
    ‘meta_value’ => array($date_1, $date_2),
    ‘orderby’ => ‘meta_value_num’,
    ‘order’ => ‘ASC’
    );
    ?>

    <?php
    // the upcoming events query
    $upcoming_query = new WP_Query( $upcoming_args );
    ?>

    <?php if ( $upcoming_query->have_posts() ) : ?>
    <!– the loop –>
    <?php while ( $upcoming_query->have_posts() ) : $upcoming_query->the_post(); ?>

    <?php the_field(‘datum’); ?>

    <?php
    if( have_rows(‘programma_tijden_2’) ): ?>
    <div id=”programma_tijden_2″>

    <?php

    // loop through rows (parent repeater)
    while( have_rows(‘programma_tijden_2’) ): the_row(); ?>
    <div class=”even-testen”>

    <!– wrap the_sub_field in elk een aparte div voor de styling –>

    <?php the_sub_field(‘tijdstip’); ?> <br />
    <?php the_sub_field(‘informatie’); ?> <br />
    <?php the_sub_field(‘extra_informatie’); ?> <br />

    </div>
    </div>

    <?php endwhile; ?>
    <?php endif;?>

    <?php endwhile; ?>

    <!– end of the loop –>

    <?php wp_reset_postdata(); ?>

    <?php else: ?>
    <p><?php _e( ‘Er zijn momenteel geen evenementen meer.’ ); ?></p>
    <?php endif; ?>
    `

    The only thing i see on my site is there are no events (the else statement)
    What am i missing?

    i’am not creating a new post, because i’am using this code. if needed i will create a new post.

    thnx in advance