• 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/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    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

    Thread Starter victorypoint

    (@victorypoint)

    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

    (@angelo_nwl)

    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

    (@victorypoint)

    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

    (@victorypoint)

    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.