Listing 2 Most Upcoming Events

I'm using the Events+ plugin and interested in listing the 2 most upcoming events on the homepage via shortcode. To be more specific, I want to take today's date, then find the 2 closest upcoming events to list (ex. event tomorrow and event next week). I'm referencing the post_type=incsub_event, but not sure how to reference today's date against the event dates.
// The Query
$db_query = new WP_Query( 'post_type=incsub_event&posts_per_page=2' );
// The Loop
while ( $db_query->have_posts() ) : $db_query->the_post();
$temp_title = get_the_title($post->ID);
$temp_link = get_permalink($post->ID);
$temp_excerpt = get_the_excerpt($post->ID);
$temp_thumb = get_the_post_thumbnail($post->ID, array(125, 125), array('class' => 'alignleft post_thumbnail', 'align' => 'left'));

// output all findings
$output .= "<div class='event-listing'><h3>$temp_thumb$temp_title</h3><p>$temp_excerpt</p><div class='button medium right'>Event Details</div></div>";
// Reset Post Data
return $output;

  • borellidesigns
    • Flash Drive

    @digitsoft - thanks for the tip! This is what I was looking for in the plugins folder and could not find. I am still having trouble getting the current timestamp within my function to compare to the events meta values. I'm trying to use the following, which is causing a white screen:
    $time = $this->get_timestamp();

    Any help would be appreciated!


  • Hakan
    • The Incredible Smush


    This is the query that I use for next upcoming events:

    global $wpdb;
    $results = $wpdb->get_results(
    	"SELECT estart.*
    	FROM $wpdb->posts wposts, $wpdb->postmeta estart, $wpdb->postmeta eend, $wpdb->postmeta estatus
    	wposts.ID=estart.post_id AND wposts.ID=eend.post_id AND wposts.ID=estatus.post_id
    	AND estart.meta_key='incsub_event_start' AND estart.meta_value > DATE_ADD(UTC_TIMESTAMP(),INTERVAL ". ( current_time('timestamp') - time() ). " SECOND)
    	AND eend.meta_key='incsub_event_end' AND eend.meta_value > estart.meta_value
    	AND estatus.meta_key='incsub_event_status' AND estatus.meta_value <> 'closed'
    	AND wposts.post_type='incsub_event' AND wposts.post_status='publish'
    	ORDER BY estart.meta_value ASC
    	LIMIT 2
    if ( $results  ){
    	foreach ( $results as $result ) {
    		$post_id = $result->post_id;
    		// Do whatever you like with the $post_id
                   $start_date_time = $result->meta_value;

    Of course you can change order, status, etc.

    I hope this helps,


  • borellidesigns
    • Flash Drive

    @Hakan - Awesome! I've implemented and this is working great!

    I am having trouble trying to retrieve an excerpt of the event listing. Event the entire content of the event listing. It looks like the excerpt logic is not used for events, which leads me to creating my own form the content. The problem is when I call get_the_content($post_id) it's outputting the contents of the entire page.

    I'm displaying 2 events in a block on the homepage. When calling get_the_content($post_id) it's displaying all of the content from the homepage.

    Is there another way I should be trying to access the contents of an entry to create my excerpts?


  • aecnu
    • WP Unicorn

    Greetings borellidesigns,

    It appears this particular topic of this ticket is now resolved/closed, if you need any further assistance please let us know.

    If it wasn't resolved, or you have any more questions related to this thread, please feel free to post them below including any new symptoms or errors and tick the 'Mark as Not Resolved (re-open)' box below the post area (or else we'll miss it!)

    Thank you for being a WPMU Dev member!

    Cheers, Joe :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.