Title: Get function no longer working
Last modified: August 20, 2016

---

# Get function no longer working

 *  Resolved [theqwertman](https://wordpress.org/support/users/theqwertman/)
 * (@theqwertman)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/)
 * 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>
       					<div class="event_detail" rel="#_EVENTURL">
       	     				<h3 class="event_link">#_EVENTLINK</h3>
       	     				<span class="event_date">#_{D M j} at #_12HSTARTTIME</span>
       					</div>
       				</div>';
   
       	$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);
       				$events_count++;
       			}
       		}else{
       			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');
       ```
   
 * [http://wordpress.org/extend/plugins/events-manager/](http://wordpress.org/extend/plugins/events-manager/)

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

 *  [agelonwl](https://wordpress.org/support/users/angelonwl/)
 * (@angelonwl)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178261)
 * 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 (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178268)
 * looks ok to me, try angelonwl’s suggestion
 *  Thread Starter [theqwertman](https://wordpress.org/support/users/theqwertman/)
 * (@theqwertman)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178275)
 * 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?
 *  [agelonwl](https://wordpress.org/support/users/angelonwl/)
 * (@angelonwl)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178285)
 * 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 );
       ```
   
 *  Thread Starter [theqwertman](https://wordpress.org/support/users/theqwertman/)
 * (@theqwertman)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178294)
 * 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’.
 *  [agelonwl](https://wordpress.org/support/users/angelonwl/)
 * (@angelonwl)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178295)
 * 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?
 *  Thread Starter [theqwertman](https://wordpress.org/support/users/theqwertman/)
 * (@theqwertman)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178298)
 * 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: [http://tinypic.com/r/33bhkk3/6](http://tinypic.com/r/33bhkk3/6)
 * 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 (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178299)
 * 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.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [empty](https://wordpress.org/support/topic-tag/empty/)
 * [events](https://wordpress.org/support/topic-tag/events/)
 * [get](https://wordpress.org/support/topic-tag/get/)
 * [manager](https://wordpress.org/support/topic-tag/manager/)
 * [upgrade](https://wordpress.org/support/topic-tag/upgrade/)

 * 8 replies
 * 3 participants
 * Last reply from: [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/get-function-no-longer-working/#post-3178299)
 * Status: resolved