Support

Account

Home Forums Backend Issues (wp-admin) Show only Upcoming event dates

Solving

Show only Upcoming event dates

  • I have a custom post type for events, with a field to display the event_date. At the moment, my code pulls in EVERY event. I need to to only pull in events that have NOT passed.

    Any advice on how I can only select posts that occur in the future? That is, show only UPCOMING EVENTS. My query so far that works to pull in ALL dates…

    <?php
            $args=array(        
            'post_type' => 'tour-date',        
            'orderby'=> 'event_date',        
            'order' => 'ASC'        
            );        
            $my_query = null;        
            $my_query = new WP_Query($args);        
            if( $my_query->have_posts() ) {        
            echo '';        
            $i = 0;        
            while ($my_query->have_posts()) : $my_query->the_post();        
            if($i % 3 == 0) { ?> 
          <?php
            }        
            ?>
  • Hi @lowercase,

    Thanks for the post.

    To query all future events, you will need to incorporate a meta_query within your $args array.

    Your code should then look like so:

    <?php
           $today = date('Ymd');
            $args=array(        
            'post_type' => 'tour-date',        
            'meta_query' => array(
    		array(
    	        'key'		=> 'event_date',
    	        'compare'	=> '>',
    	        'value'		=> $today,
    	    )       
            ),
           );       
                  
            // get posts
            $posts = get_posts($args);
            ?>
    
  • Hello, please how to display active events first then the expired events , i need code!

    am using ACF 5.7.10

    Screenshot :
    https://imagehost.imageupload.net/2020/04/23/FireShot-Capture-024—Evenements—mesloisirs—www.creativejobgroup.com.jpg

    please please help me , am beginner on ACF

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

The topic ‘Show only Upcoming event dates’ is closed to new replies.