Looking to query past events from today to 100 days ago.

I have tried everything, and searched everywhere, and I can not find where I can list past events using a wp_query.

Please help!

  • Sajid
    • DEV MAN’s Sidekick

    Hello Jason Heien :slight_smile:

    I have modified the query provided in other thread to get events between today and 100 days ago.

    $current_date = current_time('mysql'); // current time in YYYY-MM-DD HH:MM:SS format
    	$days_ago = date('Y-m-d h:i:s', strtotime( '-100 days' ));
            //$tomorrow = date('Y-m-d h:i:s', strtotime( ' tomorrow ' ));
    	//$yesterday = date('Y-m-d h:i:s', strtotime( ' yesterday ' ));
    	$args1 = array(
    	    'post_type' => 'incsub_event',
    	    'posts_per_page' => '3',
    		'meta_query' => array(
    				'key' => 'incsub_event_start',
    				'value' => $days_ago,
    				'compare' => '>',
    				'key' => 'incsub_event_start',
    				'value' => $current_date,
    				'compare' => '<',
    	// Custom query.
    	$query1 = new WP_Query( $args1 );
    	// Check that we have query results.
    	if ( $query1->have_posts() ) :
    	        // Start looping over the query results.
    	        while ($query1 -> have_posts()) : 
    	            $query1 -> the_post(); 
    	            get_template_part( 'content', 'event' ); 
    	// Restore original post data.

    I tested it with two days interval and it worked for me.

    Also, the above code is based on incsub_event_start date custom field instead of default WordPress publish date.

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.