Skip to content

Instantly share code, notes, and snippets.

@slimndap
Last active February 19, 2017 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimndap/6d74aa02b5bc679faedfd53b4dba112c to your computer and use it in GitHub Desktop.
Save slimndap/6d74aa02b5bc679faedfd53b4dba112c to your computer and use it in GitHub Desktop.
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
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