• Resolved Michael Polzella

    (@neversosimple)


    Hi, I was wondering if anyone would be able to look at my code and help me out.

    I’m developing a website for a client and they want to have a monthly dropdown box with the events for that month. I found some code to use for it and have modified it to fit my needs, but I am coming up with an issue with past events. Only events that have started between my date arguments OR are upcoming are displaying. The attached code is for January 2017, but none of the events are showing. I assume it’s because they are in the past. Would anyone be able to help me? Thanks in advance. ??

    <?php
    	global $post;
    	$post->ID;
            $start = "2017-01-01";
            $end = "2017-01-31";
    	$today = date( 'Y-m-d H:i:s');
        $tribe_events_post_type = 'tribe_events';
        $tribe_events_post_paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $tribe_events_post_args = array( 
            'post_type'        => $tribe_events_post_type,
            'post_status'      => 'publish',
            'posts_per_page'   => -1, 
            'paged' 		   => $tribe_events_post_paged,
            'caller_get_posts' => -1,
    		'meta_query' => array(
    		array(
    			'key' => '_EventStartDate',
    			'value' => array($start, $end),
    			'compare' => 'between',
    			)
    		),
    		'orderby'=>'_EventStartDate',
            'order'            => 'ASC'
        );
        $tribe_events_postloop = new WP_Query( $tribe_events_post_args );
        if( $tribe_events_postloop->have_posts() ) 
        {
        	echo '<ul>';
            while ( $tribe_events_postloop->have_posts() ) : $tribe_events_postloop->the_post();
             $business_title = get_the_title();
            ?>
            <li><a href="<?php echo get_the_permalink();?>"><span><?php echo tribe_get_start_date(); ?></span> <strong><?php echo get_the_title();?></a> - </strong><?php echo get_the_content();?></li>
           <?php
             endwhile;
            ?>
            <?php
        	echo '</ul>';
        }
        wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    <?php 
    if(function_exists('wp_pagenavi')) 
    { 
        echo wp_pagenavi( array( 'query' => $tribe_events_postloop ) );
    
    }
    ?>
  • The topic ‘Custom query to pull events between specific dates’ is closed to new replies.