• Resolved Matthew Pollard

    (@matthewpolld)


    This code is for taxonomy-event-categories.php. Each event category on my site has its own page. The code below shows the events in the correct category pages of the site.

    It shows events that have passed as well as ones in the future. I only want it to show future events. For some reason, my code is showing past events as well, please can someone tell me what needs to be changed? I would be very grateful.

    <?php
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $termst = $term->slug;
    $today = getdate ();
    $args = array(
      'post_type' => 'event',
      'tax_query' => array(
        array(
          'taxonomy' => 'event-categories',
          'field'    => 'slug',
          'terms'    => $termst,
                'posts_per_page' => -1,
          'meta_key' => '_event_start_date',
          'meta_query' => array( array( 'meta_key' => '_event_start_date' , 'meta_value' => $today, 'compare' => '>=' , 'type' => 'date')),
          'orderby' => 'meta_value'
              ),
      ),
    );
    $query = new WP_Query( $args );
       if($query ->have_posts()) :
          while($query ->have_posts()) :
             $query ->the_post();
     ?>
             <h1><?php the_title() ?></h1>
          <?php   echo ' - '. get_post_meta($id, '_event_start_date', true)    ?>
          <?php
          endwhile;
       else:
    ?>
          Oops, there are no posts.
    
    <?php
       endif;
    ?>

    https://wordpress.org/plugins/events-manager/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Using WP_Query how can I show only events that are in the future?’ is closed to new replies.