Last active
October 11, 2019 12:56
-
-
Save Pebblo/c9ced882dd7ea826c612661939a84ea2 to your computer and use it in GitHub Desktop.
A Shortcode to pull the next upcoming event and return 'Next course {start date} - Register'. You can set the category_slug parameter on the shortcode to pull a specific event category.
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 // Please do not include the opening PHP tag if you already have one. | |
function display_next_upcoming_event( $attributes = array() ) | |
{ | |
$where_conditions = array( | |
'Datetime.DTT_EVT_start' => array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ) | |
); | |
if (! empty($attributes['category_slug']) ) { | |
$where_conditions['Term_Relationship.Term_Taxonomy.Term.slug'] = 'first'; | |
} | |
$event = EEM_Event::instance()->get_one( | |
array( | |
$where_conditions | |
) | |
); | |
if( $event instanceof EE_Event) { | |
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $event->ID(), false, false, 1 ); | |
$datetime = end($datetimes); | |
if( $datetime instanceof EE_Datetime ) { | |
$start_date = $datetime->start_date(); | |
$permalink = $event->get_permalink(); | |
return "Next course $start_date - <a href='$permalink'>Register</a>"; | |
} | |
} | |
} | |
add_shortcode('NEXT_UPCOMING_EVENT','display_next_upcoming_event'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment