Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DigitalEssence/29ae4834d46b7112a5c5fc4ff386d440 to your computer and use it in GitHub Desktop.
Save DigitalEssence/29ae4834d46b7112a5c5fc4ff386d440 to your computer and use it in GitHub Desktop.
WordPress - EventManager - Show other events in same category
<?php
if (class_exists('EM_Events')) {
$currentid = $EM_Event->id; //get and store the current event id
$cats = $EM_Event->get_categories(); //get the categories for the current event
$cat_ids = $cats->get_ids(); //get the ids for the categories of the current event
$cat_ids_strg = implode(',', $cat_ids); //make a comma seperated string of category ids
//use categories to find similar events
$sim_events = EM_Events::get(array('limit'=>9,'category'=>$cat_ids_strg,'orderby'=>'start_date')); //build an array of up to 9 events that are similar to the current event
$sim_events_ids = array();
$adj_sim_events_ids = array();
foreach ($sim_events as $EM_Event) {
if ($EM_Event->id != $currentid) {
$sim_events_ids[] = $EM_Event->id; //step thru the similar events and pull out just the event ids
}
}
$adj_sim_events_ids_strg = implode(',', $sim_events_ids); //make a comma seperated string of adjusted category ids
echo EM_Events::output( array('limit'=>8,'event'=>$adj_sim_events_ids_strg,'orderby'=>'start_date') ); //output only the adjusted similar event ids
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment