Created
February 19, 2013 18:18
-
-
Save stephenharris/4988415 to your computer and use it in GitHub Desktop.
Get 'todays' event with Event Organiser. (Today means running today - might have started before today).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns today's event (or false if it one doesn't exist). If there is more than one it simply returns the first one. | |
* By 'today' I mean running today (though could have started earlier). You can change altering it slightly. | |
* | |
* @see http://wp-event-organiser.com/documentation/function/eo_get_events/ | |
* | |
*/ | |
function sh_get_todays_event(){ | |
//Get events running today | |
$events = eo_get_events( array( | |
'event_start_before' => 'today', | |
'event_end_after' => 'today', | |
'numberposts' => 1, | |
)); | |
if( !$events ){ | |
//If no events, just return false | |
return; | |
}else{ | |
return array_pop( $events); | |
} | |
} | |
/* | |
* Usage: | |
* | |
* global $post; //This stuff is needed for the title/content! | |
* | |
* if( $post = sh_get_todays_event() ){ | |
* | |
* setup_postdata(); //Needed for the content! | |
* | |
* echo '<h3>'.get_the_title().'</h3>'; | |
* | |
* the_content(); | |
* | |
* //Clean up after ourselves | |
* wp_reset_postdata(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment