Advertisement
eventsmanager

Migrate Events Manager Events and Data

Mar 26th, 2017
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.67 KB | None | 0 0
  1. <?php
  2. /*
  3. Below are some instructions on how to import data from Events Manager from one site to another in situations where the destination site already has other content
  4.  
  5. 1. Use the WP Exporter to export the Event, Location and Recurring Event Post Types
  6.   a. For each one, open a text editor and do a search and replace of the following:
  7.         Search:     </wp:post_id>
  8.         Replace:    000</wp:post_id>
  9. 2. Copy and add/overwrite all wp_em_ prefixed tables and if you don't have no-user bookings you'd need to also copy the wp_users and wp_usermeta tables
  10.   a. For the wp_em_event and wp_em_location tables (prefixes may vary), run these two queries:    
  11.         UPDATE `wp_em_locations` SET post_id=post_id*1000;
  12.         UPDATE `wp_em_locations` SET post_id=post_id*1000;
  13. 3. Disable ALL plugins and theme on destination, including EM
  14. 4. Install Custom Post Type UI plugin and import this CPT setting and for Post Types
  15.  
  16. {"event":{"name":"event","label":"Events","singular_label":"Event","description":"","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","show_in_rest":"false","rest_base":"","has_archive":"false","has_archive_string":"","exclude_from_search":"false","capability_type":"post","hierarchical":"false","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":"","supports":["title","editor","thumbnail"],"taxonomies":[],"labels":{"menu_name":"","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","items_list_navigation":"","items_list":"","attributes":""},"custom_supports":""},"location":{"name":"location","label":"Locations","singular_label":"Location","description":"","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","show_in_rest":"false","rest_base":"","has_archive":"false","has_archive_string":"","exclude_from_search":"false","capability_type":"post","hierarchical":"false","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":"","supports":["title","editor","thumbnail"],"taxonomies":[],"labels":{"menu_name":"","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","items_list_navigation":"","items_list":"","attributes":""},"custom_supports":""},"event-recurring":{"name":"event-recurring","label":"Recurring Events","singular_label":"Recurring Event","description":"","public":"true","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","show_in_rest":"false","rest_base":"","has_archive":"false","has_archive_string":"","exclude_from_search":"false","capability_type":"post","hierarchical":"false","rewrite":"true","rewrite_slug":"event-recurring","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":"","supports":["title","editor","thumbnail"],"taxonomies":[],"labels":{"menu_name":"","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","items_list_navigation":"","items_list":"","attributes":""},"custom_supports":""}}
  17.  
  18. And this one for Taxonomies
  19.  
  20. {"event-categories":{"name":"event-categories","label":"Event Categories","singular_label":"Event Category","description":"","public":"true","hierarchical":"false","show_ui":"true","show_in_menu":"true","show_in_nav_menus":"true","query_var":"true","query_var_slug":"","rewrite":"true","rewrite_slug":"event-categories","rewrite_withfront":"1","rewrite_hierarchical":"0","show_admin_column":"false","show_in_rest":"false","show_in_quick_edit":"","rest_base":"","labels":{"menu_name":"","all_items":"","edit_item":"","view_item":"","update_item":"","add_new_item":"","new_item_name":"","parent_item":"","parent_item_colon":"","search_items":"","popular_items":"","separate_items_with_commas":"","add_or_remove_items":"","choose_from_most_used":"","not_found":"","no_terms":"","items_list_navigation":"","items_list":""},"object_types":["event"]},"event-tags":{"name":"event-tags","label":"Event Tags","singular_label":"Event Tag","description":"","public":"true","hierarchical":"false","show_ui":"true","show_in_menu":"true","show_in_nav_menus":"true","query_var":"true","query_var_slug":"","rewrite":"true","rewrite_slug":"event-tags","rewrite_withfront":"1","rewrite_hierarchical":"0","show_admin_column":"false","show_in_rest":"false","show_in_quick_edit":"","rest_base":"","labels":{"menu_name":"","all_items":"","edit_item":"","view_item":"","update_item":"","add_new_item":"","new_item_name":"","parent_item":"","parent_item_colon":"","search_items":"","popular_items":"","separate_items_with_commas":"","add_or_remove_items":"","choose_from_most_used":"","not_found":"","no_terms":"","items_list_navigation":"","items_list":""},"object_types":["event"]}}
  21.  
  22. 5. Make sure this file is included within your wp-content/plugins or wp-content/mu-plugins folder on your destination site.
  23. 6. Use the importer file to import events, locations and recurring events
  24. 7. Disable 'Custom Post Types UI' plugin.
  25. 8. Activate EM again.
  26.  
  27. */
  28. /**
  29.  * Assumes that the importer is importing post IDs that don't exist on this new system, or are the same between destination/source
  30.  * @param unknown $post_id
  31.  * @param unknown $post
  32.  * @return unknown|boolean
  33.  */
  34. function my_wp_import_existing_post_mod( $post_id, $post ){
  35.     global $importing_post_ids, $wpdb;
  36.     if( empty($importing_post_ids[$post['post_type']]) ){
  37.         $importing_post_ids[$post['post_type']] = $wpdb->get_col($wpdb->prepare('SELECT ID FROM '.$wpdb->posts.' WHERE post_type=%s', $post['post_type']));
  38.     }
  39.     if( in_array($post['post_id'], $importing_post_ids[$post['post_type']]) ){
  40.         return $post['post_id'];
  41.     }
  42.     return false;
  43. }
  44. add_filter('wp_import_existing_post', 'my_wp_import_existing_post_mod', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement