I'm trying to display past and future events using a wordpress query. I'm able to query future events and even events that are on the same date as the current date.

But, when i use less than or equals to in the query, nothing returns at all.

Here's the frontend for reference. https://www.epmsonline.com/speaker/pam-roberts/

        $terms = get_the_terms( $post->ID , 'event_speaker', 'string');
//Pluck out the IDs to get an array of IDS
$term_ids = wp_list_pluck($terms,'term_id');
            $current = current_time( 'Y-m-d' );

                $the_query = new WP_Query( array(
                    'post_type' => 'tribe_events',
                    'meta_key' => '_EventStartDate',
                    'tax_query' => array(
                        array (
                             'taxonomy' => 'event_speaker',
                        'field' => 'id',
                        'terms' => $term_ids,
                        'operator'=> 'IN' //Or 'AND' or 'NOT IN'
                    'meta_query' => array(
                            'key'     => '_EventStartDate',
                            'value'   => $current,
                            'compare' => '<=',
                             'type' => 'DATE'

                ) );

            while ( $the_query->have_posts() ) :
                $the_query->the_post(); ?>
                   <div class="upcoming-events">
                    <h2><?php the_title(); ?><br><?php echo tribe_get_start_date(); ?> - <?php echo tribe_get_end_time(); ?></h2>
                   </div><!-- upcoming events-->

            <?php endwhile;

            /* Restore original Post Data 
             * NB: Because we are using new WP_Query we aren't stomping on the 
             * original $wp_query and it does not need to be reset.
            wp_reset_postdata(); ?>
  • In tax_query you use 'field' => 'id' but it should be 'field' => 'term_id'. What format does the date have in the _EventStartDate field, YYYY-MM-DD? – nmr Aug 3 '19 at 18:30
  • Yes, it should be YYYY-MM-DD – chris Aug 3 '19 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.