Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created February 12, 2019 02:36
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 joshfeck/cb2c0c00e15dbbd3489e35187722a402 to your computer and use it in GitHub Desktop.
Save joshfeck/cb2c0c00e15dbbd3489e35187722a402 to your computer and use it in GitHub Desktop.
remove a specific category if no category is set in the Event Espresso calendar shortcode
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter(
'FHEE__EED_Espresso_Calendar__get_calendar_events__query_params',
'mdeyerinkc_remove_category_calendar_filter',
10,
7
);
function mdeyerinkc_remove_category_calendar_filter(
$query_params,
$category_id_or_slug,
$venue_id_or_slug,
$public_event_stati,
$start_date,
$end_date,
$show_expired
) {
// is a category set in the shortcode?
if(is_array($category_id_or_slug )) {
return $query_params; // yes, get out!
}
// still here, so there must be a category to exclude
// get all cat ids
$event_category_ids = array();
// create loop to insert IDs to array
$event_categories = get_terms( array(
'taxonomy' => 'espresso_event_categories',
'hide_empty' => false
) );
foreach( $event_categories as $cat ) {
if ($cat->term_id != 67) { // exclude this category only!
$event_category_ids[] = $cat->term_id;
}
}
$query_params[0]['OR*category'] = array(
'Event.Term_Taxonomy.term_id' => array( 'in', $event_category_ids ),
);
return $query_params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment