Facebook events importing: custom code
-
Hi,
It’s been a long time I’d like to implement events from facebook to EM:
I tried a lot of plugins but none solve my problem completely.So I decided to implement it manually:
I used facebook SDK and I can retrieve what I need from my facebook page.
Great.But I don’t succeed to insert in EM the events I got from facebook.
Here my code in my cycle where I loop facebooks events:
//check if event it's already been imported $args = array ( 'post_type' => 'event', 'posts_per_page' => -1, 'meta_key' => '_facebook_event_id', 'meta_query' => array( 'key' => '_facebook_event_id', 'value' => $event_id, ), ); $loop = new WP_Query( $args ); //if presents, I update data if( $loop->have_posts() ){ // se l'evento presente aggiorno i suoi dati //$u++; while ( $loop->have_posts() ) : $loop->the_post(); $post_id = get_the_ID(); $post_information = array( 'post_type' => 'event', 'ID' => $post_id, 'post_title' => wp_strip_all_tags($e->name), 'post_content' => wp_strip_all_tags($e->description), ); wp_update_post( $post_information ); endwhile; }else{ // else I add event $post_information = array( 'post_type' => 'event', 'post_title' => wp_strip_all_tags($e->name), 'post_content' => wp_strip_all_tags($e->description), 'post_status' => 'publish', ); // insert event post in WP $post_id = wp_insert_post( $post_information ); // insert event in events table $wpdb->insert( 'SqE_em_events', array( 'event_owner' => 1, 'event_status' => 1, 'event_name' => wp_strip_all_tags($e->name), 'event_start_time' => $starTime, 'event_end_time' => $endTime, 'event_start_date' => $startDate, 'event_end_date' => $endDate, 'post_content' => wp_strip_all_tags($e->description), 'event_rsvp' => 0, 'post_id' => $post_id, 'location_id' => $location_id ), array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d' ) ); } // update meta for event add_post_meta($post_id, '_facebook_event_id', $eId, true); update_post_meta($post_id,'_event_start_time',$starTime); update_post_meta($post_id,'_event_end_time',$endTime); update_post_meta($post_id,'_event_start_date',$startDate); update_post_meta($post_id,'_event_end_date',$endDate); update_post_meta($post_id,'_event_status', 1); update_post_meta($post_id,'_location_status', 1);
Can someone help me to insert manually and safely an event into EM?
PS: If I use this, Have I to add some includes in php file?
This doesn’t work for me.
$EM_Event = new EM_Event(); $EM_Event->event_name = $evt_name; $EM_Event->event_start_date = $evt_start_d; $EM_Event->event_start_time = $evt_start_t; $EM_Event->event_end_date = $evt_end_d; $EM_Event->event_end_time = $evt_end_t; $EM_Event->start = strtotime($EM_Event->event_start_date." ".$EM_Event->event_start_time); $EM_Event->end = strtotime($EM_Event->event_end_date." ".$EM_Event->event_end_time); $EM_Event->event_all_day = $evt_all_day; $EM_Event->save();
Really thanks guys
Viewing 14 replies - 1 through 14 (of 14 total)
Viewing 14 replies - 1 through 14 (of 14 total)
- The topic ‘Facebook events importing: custom code’ is closed to new replies.