Forum Replies Created

Viewing 15 replies - 16 through 30 (of 76 total)
  • Thread Starter fersamp

    (@fersamp)

    Hi,
    I’m getting all future events, so I think that filter is not working.
    The EM version is 5.6.3.

    Try to add in your functions.php this:

    add_action('init', 'my_custom_init');
    function my_custom_init() {
    	add_post_type_support( 'event', 'publicize' );
    	add_post_type_support( 'event-recurring', 'publicize' );
    	add_post_type_support( 'location', 'publicize' );
    }

    Hi ronfedele,
    I think that the problem is not Facebook import or integration, but how to insert event through code, without using backend.

    There are a lots of working codes to import event from facebook.

    In these days I managed to connect to my facebook event page events:
    if you want I could send you the code, even with google geolocalization code to convert address into GPS Coordinate or vice versa, but the problem I personally had is how to save data into EM and display events in backend.
    I’m very close to do it, anyway πŸ˜‰

    EM is a great plugin, without doubts, but I don’t understand why a simple event creation is so difficult or why support can’t help us about…

    Thread Starter fersamp

    (@fersamp)

    Thank you Ron, you are very kind, but I made all my site according to Events Manager, so I can’t change plugin.

    Thread Starter fersamp

    (@fersamp)

    I’m not asking for a new feature that requires hard work, I’m simply asking how events are added until now through code.

    I’m wondering for example what happens when you click “new event” and fill the fields with event name, address, location ecc…

    I hanged myself with many insert directly on the db, but it was not enough because then the events are not recognized by the backend, so there must necessarily be a simpler and more high level solution.

    I really don’t understand why is so difficult add a new event without backend. πŸ™

    Thread Starter fersamp

    (@fersamp)

    Update:
    Do $event->save() has to return true, isn’t true?

    Thread Starter fersamp

    (@fersamp)

    Hi Rob,
    thank you for help, but I think that inserts are correct because I see the rows that are inserted.

    Instead, I saw that in

    $event = new EM_Event($wpdb->insert_id);
    $event->set_status(1, true);
    $result = $event->save();

    $event->save() returns false, even if $wpdb->insert_id is the correct event id just inserted in em_events.
    I don’t understand why….

    Thread Starter fersamp

    (@fersamp)

    I added global $EM_Event;, nothing changed.

    Insert are correct:
    1) post event is added into posts table;
    2) location event is added into posts table;
    2) location event is added in em_locations;
    4) event is added in EM table;
    3) post and location meta are added;

    After these inserts, I don’t see new event in backend, but seems all data are inserted in db.

    How does they work $event = new EM_Event($wpdb->insert_id);
    and save() ?
    I think I miss something…

    Thread Starter fersamp

    (@fersamp)

    update:

    I succeded to add manually rows to correct tables:

    I added event and location post in post table, event in event table, location in location table and correct postmeta data in postmeta table…
    Everything seems correct, but I still not see new event in events list in backend.
    Here my code, in the events cycle for to add:

    $args = array(
    'post_type' => 'event',
    'meta_query' => array(
    array(
    'key' => '_facebook_id',
    'value' => $event_id,
    'compare' => '=')
    )
    );
    
    $check = get_posts($args);
    
    if (!empty($check)) {
    	continue;
    }else{
    
    	$_event_start_date = date('Y-m-d', strtotime($e->start_time));
    	$_event_end_date = date('Y-m-d', strtotime($e->end_time) + 3600);
    	$_event_start_time = date('H:i:s', strtotime($e->start_time));
    	$_event_end_time = date('H:i:s', strtotime($e->end_time) + 3600);
    
    	$id = wp_insert_post(array(
    	'post_type' => 'event',
    	'post_title' => wp_strip_all_tags($e->name),
    	'post_author' => '1',
    	'post_content' => wp_strip_all_tags($e->description),
    	'post_status' => 'publish',
    	));
    
    	global $wpdb;
    	$query = 'select * from ' . $wpdb->prefix . 'em_locations where location_name like "%' . $wpdb->esc_like($locationName) . '%"';
    
    	$location_row = $wpdb->get_row($query);
    
    	if ($location_row) {
    
    		$location_id = $location_row->location_id;
    
    	} else {
    
    		$post_id = wp_insert_post(array(
    		'post_type' => 'location',
    		'post_title' => $locationName,
    		'post_status' => 'publish',
    		));
    
    		update_post_meta($post_id, '_location_town', 'Roma');
    		update_post_meta($post_id, '_location_country', 'Italia');
    		update_post_meta($post_id, '_location_address', $locationName);
    		update_post_meta($post_id, '_location_state', 'Italia');
    
    		$queryLocation = 'insert into ' . $wpdb->prefix . 'em_locations '
    		. 'set post_id="' . $wpdb->escape($post_id) . '",'
    		. 'location_name="' . $wpdb->escape($locationName) . '",'
    		. 'location_address="' . $wpdb->escape($locationName) . '",'
    		. 'location_town="Roma",'
    		. 'location_state="Italia",'
    		. 'location_status="1",'
    		. 'location_country="Italia",'
    		. 'blog_id="0",'
    		. 'location_slug="' . $wpdb->escape(sanitize_title($locationName)) . '",'
    		. 'location_latitude="' . $wpdb->escape(sanitize_title($lat)) . '",'
    		. 'location_longitude="' . $wpdb->escape(sanitize_title($long)) . '",'
    		. 'location_owner=1';
    
    		$wpdb->query($queryLocation);
    
    		$location_id = $wpdb->insert_id;
    		if($location_id){
    
    			update_post_meta($post_id, '_location_status', 1);
    			update_post_meta($post_id, '_location_longitude', $long);
    			update_post_meta($post_id, '_location_latitude', $lat);
    			update_post_meta($post_id, '_location_country', 'Italia');
    			update_post_meta($id, '_location_id', $location_id);
    		}
    
    	}
    
    	$sqlEvent = "INSERT INTO " . $wpdb->prefix . "em_events (event_owner, event_status, event_name, event_start_time, event_end_time, event_start_date, event_end_date, post_content, event_rsvp, post_id, location_id)
    				values (
    				1,
    				1,
    				'" . wp_strip_all_tags($e->name) . "' ,
    				'" . $_event_start_time . "' ,
    				'" . $_event_end_time . "' ,
    				'" . $_event_start_date . "' ,
    				'" . $_event_end_date . "' ,
    				'" . wp_strip_all_tags($e->description) . "',
    				0,
    				'" . $id . "',
    				'" . $location_id . "'
    				)";
    
    	$wpdb->query($sqlEvent);
    
    	$event = new EM_Event($wpdb->insert_id);
    	$event->set_status(1, true);
    	$result = $event->save();
    
    	update_post_meta($id, '_event_end_date', $_event_end_date);
    	update_post_meta($id, '_event_end_time', $_event_end_time);
    	update_post_meta($id, '_event_start_date', $_event_start_date);
    	update_post_meta($id, '_event_start_time', $_event_start_time);
    	update_post_meta($id, '_location_id', $location_id);
    	update_post_meta($id, '_facebook_id', $event_id);

    I’m not sure about last part:

    $event = new EM_Event($wpdb->insert_id);
    $event->set_status(1, true);
    $result = $event->save();

    WHAT I HAVE TO DO MORE? πŸ™

    Thread Starter fersamp

    (@fersamp)

    Update: I tested that code again and again: no events added in em_events, posts or postmeta table.

    I studied a lot the EM process event creation and I think these are tables implicated:

    1) TABLE posts, creates event and location row:
    – the event is created as post type = ‘event’.
    – the base information like title and content are set
    – status is set as ‘publish’

    – the location is created as post type = ‘location’.
    – the base information like title and content are set
    – status is set as ‘publish’

    2) TABLE postmeta, creates event and location row meta:
    – all event meta like _event_id, _event_id, _location_id etc…
    -all location meta like _location_address, _location_town,_location_state etc…

    3) TABLE em_locations, location is inserted with post_id, location_name ecc.
    post_id is the id of post type

    4) TABLE em_events, event is inserted with name, location address, stardate ecc.
    I suppose info data event are obtained from metapost table.

    I tried to replace these flow with queries, but in vain…

    Thread Starter fersamp

    (@fersamp)

    Hi caimin_nwl,
    I tried with this

    $EM_Event = new EM_Event();
    $EM_Event->event_name = $e->name;
    $EM_Event->event_start_date = $_event_start_date;
    $EM_Event->event_start_time = $_event_start_time;
    $EM_Event->event_end_date = $_event_end_date;
    $EM_Event->event_end_time = $_event_end_time;
    _log('FRA: aggiunta evento: ' . $e->name . ' startdate ' . $_event_start_date . ' enddate ' . $_event_end_date );
    
    $EM_Event->event_all_day = 0;
    $EM_Event->save();

    but event is not added.
    Log says correct data: name, startdate and enddate like ‘2016-04-07’.

    It’s a lot of days I’m fighting with this problem πŸ™

    Is there someone that succeded to add an event with $EM_Event = new EM_Event();?
    Have I to add an import to use that method?

    Thread Starter fersamp

    (@fersamp)

    I tried with query but nothing…

    Events data are correct to 100%.

    How can I add a new event to EM manually?

    Thread Starter fersamp

    (@fersamp)

    I’m using it in a shortcode in custom function.php…
    I don’t think is invocation problem…Have I to add some include to use new EM_Event()?

    Thread Starter fersamp

    (@fersamp)

    After months of hard work, I finished my events tab filters…. it WORKS EVERYTHING.

    REALLY THANK YOU ANGELO_NWL πŸ™‚

    Thread Starter fersamp

    (@fersamp)

    Hi angelo_nwl,
    I extracted that code from em-events.php line 56.

    It worked before I added ajax=1 in the first tab for another filter.

    Thank you for tutorial link, but I can’t find what I need: I found “Adding Custom Event Search Form Fields” tutorial, this only “add a field to the search form so visitors can search and filter events by Style”.

    I need instead to use search form in my home page, do you know some code I could use?

    Really thank you for your precious help

Viewing 15 replies - 16 through 30 (of 76 total)