• Hello, I am trying to figure out a way to add a similar events list to the bottom of the single event page, but in listing the similar events I would like to exclude the event shown on the single page.

    Any ideas on how I could accomplish this would be greatly appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter switchskier

    (@switchskier)

    My plan is to get the current event id and categories, then do an event search using only those categories, output search result event ids to an array, test each id in the array to see if it is the same as the current id, if the id is different build a string of comma separated ids, then use:
    EM_Events::output(array('event'=>'MY-CREATED-ID-STRING')

    I am having trouble pulling the category id’s from the current event. Please help.

    Did you try to use placeholders to get category id like #_CATEGORYID?

    http://wp-events-plugin.com/documentation/placeholders/

    Thread Starter switchskier

    (@switchskier)

    For anyone interested in similar events, this is how I did it. Suggestions welcome.

    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();
    	foreach ($sim_events as $EM_Event) {
    		$sim_events_ids[] = $EM_Event->id; //step thru the similar events and pull out just the event ids
    	}
    	$adj_sim_events_ids = array();
    	foreach ($sim_events_ids as $key => $value) {
    		if ($value != $currentid) { //step thru the similar events ids and pull out the current event id
    			$adj_sim_events_ids[] = $value;
    		}
    	}
    	$adj_sim_events_ids_strg = implode(',', $adj_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
    }

    you can make it shorter:

    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
    }
    Thread Starter switchskier

    (@switchskier)

    @agelonwl Cool! Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘[Plugin: Events Manager] Similar events on single event page’ is closed to new replies.