Skip to content

Instantly share code, notes, and snippets.

Last active February 19, 2017 12:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Adds a [current_event] shortcode that displays the event that is currently on.
* Get the HTML to display the current event.
* @param array $args The shortcode arguments.
* @param string $template The shortcode template.
* @return string
function get_current_event_html( $args, $template = false ) {
global $wp_theatre;
// Get the last event that started.
$events = $wp_theatre->events->get(
'limit' => 1,
'end' => 'now',
'order' => 'desc',
// Bail if no events are found.
if ( empty( $events) ) {
// Bail if last event has already ended.
if ( $events[0]->datetime( true ) < time() ) {
// Return the HTML of the event.
return $events[0]->html( $template );
add_shortcode('current_event', 'get_current_event_html');
Copy link

calexbrown commented Feb 18, 2017

Okay... Got it figured out!!!!

That would return the last event ever set on each page. So it was doing half of it's job!

By modifying the Get events section to only do the production ID, it just pulls that production!!!

// Get the  event based on post ID started.
	$events = $wp_theatre->events->get(
			   'production' => get_the_id(),	

It seems to work for me for now.. I'm going to keep an eye out on this baby. I pulled this section of code from the page where it shows how you can generate your own listing:

$args = array(
    'production' => get_the_id(),
    'start' => 'now'
$events = $wp_theatre->events->get($args);
foreach ($events as $event) {
    echo $event->title();
    // do other stuff with your event        

Not sure if this was a miscommunication or not, but all is well... for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment