Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds a [current_event] shortcode that displays the event that is currently on.
<?php
/**
* 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(
array(
'limit' => 1,
'end' => 'now',
'order' => 'desc',
)
);
// Bail if no events are found.
if ( empty( $events) ) {
return;
}
// Bail if last event has already ended.
if ( $events[0]->datetime( true ) < time() ) {
return;
}
// Return the HTML of the event.
return $events[0]->html( $template );
}
add_shortcode('current_event', 'get_current_event_html');
@calexbrown

This comment has been minimized.

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(
		array(
			   '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
You can’t perform that action at this time.