Created
November 22, 2012 23:23
-
-
Save stephenh1988/4133300 to your computer and use it in GitHub Desktop.
Replaces a link on the widget calendar with one that points to the a category for one of the events running on that date.
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
/** | |
* This is a code snippet that will work with Event Organiser 1.6+ | |
* At time of writing 1.6 is still in beta. | |
* This should go in a separate plug-in or functions.php | |
* Do not change the Event Organiser files - changes to EO will be lost when you upgrade. | |
* | |
* This code snippet replaces a link on the widget calendar with one that points to the a | |
* category for one of the events running on that date. It priorities the term 'foobar'. | |
* The link appends ?ondate=[some-date] to filter by events active on that date (i.e. | |
* the date on the calendar) | |
*/ | |
add_filter('eventorganiser_widget_calendar_date_link', 'myprefix_link_to_event_cat',10,3); | |
function myprefix_link_straight_to_event( $link, $date, $events ){ | |
//Note $date is a datetime object corresponding to a day in the widget calendar | |
//$events is an array of events. Currently this non empty, but I might filter all dates - so in | |
//later versions it might be non-empty. I recommend assuming it might be and do a sanity check | |
//Sanity check | |
if( !$events ) | |
return $link; | |
//Let's get all the event terms: | |
$event_cats = array(); | |
foreach( $events as $event ){ | |
$terms = get_the_terms( $event->ID, 'event-category' ); | |
if( $terms) | |
$events_cats += $terms; | |
} | |
//If no there are no event categories, abort | |
if( !$event_cats ) | |
return $link; | |
//Extract the term slugs | |
$event_slugs = wp_list_pluck( $event_cats, 'term' ); | |
//If 'foobar' is present - use that | |
if( in_array('foobar', $event_slugs) ){ | |
$slug = 'foobar'; | |
}else{ | |
//Foobar not present, just pick another category | |
$slug = array_pop( $event_slugs ); | |
} | |
//Get link to that category, and append 'ondate' | |
$link = add_query_arg('ondate',$date->format('Y-m-d'), get_term_link($slug, 'event-category')); | |
return $link; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment