Title: Geting event post data into an array
Last modified: August 30, 2016

---

# Geting event post data into an array

 *  Resolved [victorypoint](https://wordpress.org/support/users/victorypoint/)
 * (@victorypoint)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/geting-event-post-data-into-an-array/)
 * Hi. I’m writing some PHP to get event post data and put it into an array, however
   my code is breaking when it encounters the EM_Event object as follows:
 * $postType = get_post_type($postID); //returns event
    if($postType != EM_POST_TYPE_EVENT)
   return(array()); $event = new EM_Event($postID, ‘post_id’); //code is crashing
   here $location = $event->get_location(); $arrEvent = $event->to_array(); $arrLocation
   = $location->to_array();
 * In this case, my event has a post_id of 30. Do I have the syntax of the EM_Event
   object wrong?
 * Any help is appreciated.
    -Al
 * [https://wordpress.org/plugins/events-manager/](https://wordpress.org/plugins/events-manager/)

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

 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/geting-event-post-data-into-an-array/#post-6659248)
 * hi,
 * maybe you can try something like this `$EM_Event = em_get_event($post->ID, 'post_id');`
 * eg. [https://wordpress.org/support/topic/events-manager-eventslocation-pages-cant-get-sidebar?replies=21](https://wordpress.org/support/topic/events-manager-eventslocation-pages-cant-get-sidebar?replies=21)
 *  Thread Starter [victorypoint](https://wordpress.org/support/users/victorypoint/)
 * (@victorypoint)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/geting-event-post-data-into-an-array/#post-6659311)
 * Thanks Angelo for responding. I tried your suggestion as follows but still get
   the same result.
 * $postType = get_post_type($postID); //returns event
    if($postType != EM_POST_TYPE_EVENT)
   return(array()); //$event = new EM_Event($postID, ‘post_id’); //old code is crashing
   here $event = em_get_event($postID->ID, ‘post_id’); //new code is crashing here
   $location = $event->get_location(); $arrEvent = $event->to_array(); $arrLocation
   = $location->to_array();
 * -Al
 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/geting-event-post-data-into-an-array/#post-6659315)
 * I think there is a difference in the code I shared vs your posted snippet?
 * eg.
 * my code `$EM_Event = em_get_event($post->ID, 'post_id');`
 * you code is `$event = em_get_event($postID->ID, 'post_id');`
 * OR your $post var is the variable $postID ? also, can I know if you are doing
   this in a wordpress template or separate custom php file
 *  Thread Starter [victorypoint](https://wordpress.org/support/users/victorypoint/)
 * (@victorypoint)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/geting-event-post-data-into-an-array/#post-6659321)
 * Hi. Yes, I use $postID instead of $post. It’s value is passed to my function 
   as follows. My code is in separate php files for a plugin I’m developing.
 * public static function getEventPostData($postID){
    $postType = get_post_type(
   $postID); //returns event if($postType != EM_POST_TYPE_EVENT) return(array());//
   $event = new EM_Event($postID, ‘post_id’); //old code is crashing here $event
   = em_get_event($postID->ID, ‘post_id’); //new code is crashing here $location
   = $event->get_location(); $arrEvent = $event->to_array(); $arrLocation = $location-
   >to_array();
 * -Al
 *  Thread Starter [victorypoint](https://wordpress.org/support/users/victorypoint/)
 * (@victorypoint)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/geting-event-post-data-into-an-array/#post-6659340)
 * Solved. I needed to declare the $event variable before calling EM_Event. I don’t
   remember having to to do this before. I guess my host must be using newer PHP.
 * $event = null;
    $event = new EM_Event($postID, ‘post_id’);
 * -Al

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

The topic ‘Geting event post data into an array’ 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/)

 * 5 replies
 * 2 participants
 * Last reply from: [victorypoint](https://wordpress.org/support/users/victorypoint/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/geting-event-post-data-into-an-array/#post-6659340)
 * Status: resolved