Support » Plugin: Events Manager » Get function no longer working

  • Resolved theqwertman


    I updated this plugin from an old version, and the following function no longer works. I’ve narrowed down the problem to that EM_Events::get() is returning an empty array, although it should not. Before updating the plugin this worked flawlessly. How do I need to change the code to adapt to the new version?

    Part of the code in question is padded with line breaks.

    * shortcode - tpevents
    * outputs the tp events slider
    * @param unknown_type $atts
    * @return string
    function tpevents_shortcode($atts) {
    	global $EM_Event;
    	$EM_Event_old = $EM_Event; //When looping, we can replace EM_Event global with the current event in the loop
    	//Can be either an array for the get search or an array of EM_Event objects
    	extract( shortcode_atts( array(), $atts ) );
    	//define default EM query attributes
    	$defaults = array(
    		'limit' => 5,
    		'scope' => 'future',
    	$atts = wp_parse_args( $atts, $defaults );
    	//open the slider
    	$output = '
    			<div class="events_slides">
    				<div class="slides_container">';
    	$format = 	'<div class="event_slide">
    					<div class="event_img">
    	     				<a href="#_EVENTURL">#_EVENTIMAGE</a>
    					<div class="event_detail" rel="#_EVENTURL">
    	     				<h3 class="event_link">#_EVENTLINK</h3>
    	     				<span class="event_date">#_{D M j} at #_12HSTARTTIME</span>
    	$today = strtotime('today');
    	$events_count = 0;
    	$old_limit = (int)$atts['limit'];
    	$atts['limit'] = $old_limit + 1;//increase the events returned to support an expired event
    	$events = EM_Events::get($atts);
    	foreach($events as $EM_Event){
    		if($events_count < $old_limit){
    			$event_start_date = strtotime($EM_Event->start_date);
    			if($event_start_date >= $today){
    				$output .= $EM_Event->output($format);
    			break;//stop loop
    	//close the slider
    	$output .= '</div></div>';
    	//check if no events were returned
    	if($events_count == 0)
    		$debugline = print_r($atts,true);
    		$output = 'There are no events';
    	//restore existing $EM_Event
    	$EM_Event = $EM_Event_old;
    	return $output;
    add_shortcode('tpevents', 'tpevents_shortcode');

Viewing 8 replies - 1 through 8 (of 8 total)
  • I tried to paste your snippet without any modification and seems to be working fine.
    e.g. I tried this EM_Events::get() to see if its return an empty array but it returns okay

    $events = EM_Events::get($atts);
            print_r( $events );

    then I paste the shortcode in wp page like [tpevents]

    Plugin Author Marcus


    NetWebLogic Support

    looks ok to me, try angelonwl’s suggestion

    I’m passing it this [tpevents limit=”7″ category=”2″]
    Although I did try with no variables and it still didn’t work. Any suggestions on how to isolate the problem?

    have you tried my suggestion above to check the array content?

    $events = EM_Events::get($atts);
    print_r( $events );

    then add a print_r again after the foreach loop.

    foreach($events as $EM_Event){
     print_r( $EM_Event );

    Yes, I tried print_r and got an empty array.
    I was temporarily able to solve the problem by removing category=”2″ so that it’s just [tpevents limit=”7″]. Unfortunately we need the results to be limited by category.

    I noticed that the all entries in the table em_events have NULL as the value for event_category_id. I tried yet setting some of these to 2, but they still did not appear. Where else can I look for the cause of the problem?

    We’ve run into another clue, too. We aren’t able to update any of the events due to a ‘database error’.

    can I know what database error is that? and from what previous version of Events Manager you are using?

    also, did you check if events category with Id 2 still exists at Events > Events Categories then click Screen Options > click ID > apply?

    I found a partial solution! It looks like the value meta_value was changed from 2 to 9 in all of the entries in the em_meta table. Mysterious…

    Changing them back to 2 FIXES my slideshow, but I still get the following error when editing events in the interface:

    As far as I know the only change is that WordPress has been updated. What kinds of things cause this plugin to display that error?

    Plugin Author Marcus


    NetWebLogic Support

    r.e. the database error, try to see your php error logs or turn on WP_DEBUG in your wp-config.php file

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Get function no longer working’ is closed to new replies.