• Resolved Daphne C.

    (@dchristof)


    I have been trying to import events from Modern Events Calendar to WP Event Manager, unsuccessfully. I have tried exporting MEC events and importing them through WP Event Manager Migration plugin matching the columns but a lot of data such as the start and end time, Organizers and Venues and other, are not imported. Also, the Modified Date column on the backend event-listing page shows UNKNOWN as the user.

    After many failed tests I decided to write my own code to import MEC events to WP Event Manager. My events are imported with all their fields (even the Organizers and Venues) but when I try to view the page with the event listing shortcodes (I have a shortcode for each event category) i.e.
    [events show_filters=”false” event_types=”online” orderby=”event_start_date” order=”DESC”]
    the events shown include the ones that have expired even though I have the option “Hide expired listings in event archive/search.” enabled in the plugin settings.
    The only way to hide expired events is if I edit the expired events one by one and save the post even without changing anything. This tells me that something is not right during the import process.

    I would appreciate any insights on this because we are really interested in making the transition from MEC to WP Event Manager and even purchase some of the premium plugins. But we need to be able to import the events successfully.

    Here’s my code :

    
    function migrate_events() {
    
    $options = array( 
    	'post_type' => 'mec-events',
    	'post_status' => 'any',
    	'posts_per_page' => -1,
    	'meta_query'    => array(
    		array(
    			'key'     => 'mec_start_date',
    			'value'   => '2020-07-01', //date("Y-m-d"), // GET ONLY EVENTS AFTER THIS DATE
    			'compare' => '>=', // Return the ones greater than above date
    			'type' 	  => 'DATE' // Let WordPress know we're working with date
    		),
    	),		
    );
    $mec_events = get_posts( $options );
    
    if ( $mec_events ) {
    	$i=1;
    	$j=1;
    	foreach ($mec_events as $mec_event) {
    		//GET EVENT FROM MODERN EVENTS CALENDAR
    		$start_date = ''; $end_date = ''; $start_time = ''; $end_time = ''; $mec_start_time_minutes = ''; $mec_end_time_minutes = '';
    		$read_more_link = ''; $more_info_link = ''; $cost = 0; 
    		
    		$start_date = date("d-m-Y", strtotime($mec_event->mec_start_date)); 
    		$end_date = date("d-m-Y", strtotime($mec_event->mec_end_date)); 
    	
    		$start_time = $mec_event->mec_start_time_hour.':'.$mec_start_time_minutes.' '.$mec_event->mec_start_time_ampm; 
    		$end_time = $mec_event->mec_end_time_hour.':'.$mec_end_time_minutes.' '.$mec_event->mec_end_time_ampm;	
    		
    		$new_start_date = $start_date .' ' .date("H:i:s", strtotime($start_time));
    		$new_end_date = $end_date .' ' .date("H:i:s", strtotime($end_time));
    		
    		$read_more_link = $mec_event->mec_read_more;
    		$more_info_link = $mec_event->mec_more_info;
    		$cost = $mec_event->mec_cost;
    		
    		$post_id = $mec_event->ID;
    		$meta = get_post_meta($post_id);
    
    		$tax_category_terms = wp_get_post_terms( $post_id, 'mec_category', array( "fields" => "slugs" ) );
    		if ( ! empty( $tax_category_terms ) && ! is_wp_error( $tax_category_terms ) ) {
    			$cat_terms_array = array();
    			foreach ( $tax_category_terms as $cat ) {
    				$cat_terms_array[] = $cat;
    			}
    		}
    
    		$tax_type_terms = wp_get_post_terms( $post_id, 'mec_label', array( "fields" => "slugs" ) );
    		if ( ! empty( $tax_type_terms ) && ! is_wp_error( $tax_type_terms ) ) {
    			$type_terms_array = array();
    			foreach ( $tax_type_terms as $type ) {
    				$type_terms_array[] = $type;
    			}
    		}
    			
    		$mec_organizer = get_term($mec_event->mec_organizer_id);
    		echo 'organizer id: ' .$mec_event->mec_organizer_id .' with slug : ' .$mec_organizer->slug .'<br/>';
    		if($mec_organizer->slug != '') {
    			$post_data = get_page_by_path($mec_organizer->slug, OBJECT, 'event_organizer');
    			$organizer_post_id = $post_data->ID;
    		}	
    
    		$mec_venue = get_term($mec_event->mec_location_id);
    		echo 'venue id: ' .$mec_event->mec_location_id .' with slug : ' .$mec_venue->slug .'<br/>';
    		if($mec_venue->slug != '') {
    			$post_data = get_page_by_path($mec_venue->slug, OBJECT, 'event_venue');
    			$venue_post_id = $post_data->ID;
    		}
    
    			
    		//IMPORT EVENT TO WP EVENT MANAGER	
    		$event_id = wp_insert_post( 
    			array( 
    				'post_title' => $mec_event->post_title, 
    				'post_type' => 'event_listing', 
    				'post_author'    => $mec_event->post_author,
    				'comment_status' => 'closed',		
    				'post_status' => 'publish', 
    				'post_date' => $mec_event->post_date,
    				'post_modified' => $mec_event->post_modified,
    				'post_content' => $mec_event->post_content, 
    				'post_name' => $mec_event->post_name
    				) 
    			);
    			//$submitting_key = uniqid();
    			//update_post_meta( $event_id, '_submitting_key', $submitting_key );
    
    			if(!is_wp_error($event_id)){				
    				set_post_thumbnail( $event_id, $mec_event->_thumbnail_id );
    				update_post_meta( $event_id, '_event_start_date', $new_start_date ); 
    				update_post_meta( $event_id, '_event_start_time', $start_time ); 
    				update_post_meta( $event_id, '_event_end_date', $new_end_date );
    				update_post_meta( $event_id, '_event_end_time', $end_time ); 
    
    				$event_expiry_date = get_event_expiry_date($event_id);
    				update_post_meta( $event_id, '_event_expiry_date', $event_expiry_date );	
    				
    				update_post_meta( $event_id, '_registration', $more_info_link ); 
    				
    				if(count($cat_terms_array) > 0) {
    					wp_set_object_terms($event_id, $cat_terms_array, 'event_listing_category', true);
    				}	
    				if(count($type_terms_array) > 0) {
    					wp_set_object_terms($event_id, $type_terms_array, 'event_listing_type', true);
    				}	
    				if($organizer_post_id > 0) {
    					update_post_meta( $event_id, '_event_organizer_ids',  array($organizer_post_id) );
    				}	
    				if($venue_post_id > 0) {
    					update_post_meta( $event_id, '_event_venue_ids',  array($venue_post_id) );
    				}		
    
    				//test to see if updating post will fix bug with manual save for the event expiry date to work correctly
    				$data = array('ID' => $event_id,);	
    				wp_update_post( $data ); 
    				
    			} else {
    				echo '<span style="color:red;">Could not insert event!: '.$mec_event->post_title.'</span><br/>';	
    			}					
    	
    		$i++;
    	}	
    }
    
    	
    }
    • This topic was modified 1 year, 4 months ago by Daphne C..
    • This topic was modified 1 year, 4 months ago by Daphne C..
    • This topic was modified 1 year, 4 months ago by Daphne C..
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Daphne C.

    (@dchristof)

    Also I have to add that the shortcode orderby is not working for me.. For example I have this shortcode
    [events show_filters="false" event_types="online" orderby="event_start_date" order="DESC"]
    and the events appear with mixed order (the expired ones as well).

    The date format in the plugin settings is set to d/m/Y and I import the events with this format. Also, I checked a few events appearing in mixed order and they do have start and end time.

    Hi,
    If you want your events to be expired, you will have to add expiry dates of the events from the backend manually while creating them.
    That is how the functionality had been set up.
    And about the shortcode, please raise a ticket and send your backend admin details and we will try to solve it there.

    Thank You.

    Thread Starter Daphne C.

    (@dchristof)

    I have added expiry dates to the events – if you see my code I’m importing the events with expiry dates. Still they show on the events page. The only way to hide them is if I edit the expired events one by one and save the post. That’s why I’m wondering if the problem lies on the import process.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with import’ is closed to new replies.