Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- 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
- 1. Use the WP Exporter to export the Event, Location and Recurring Event Post Types
- a. For each one, open a text editor and do a search and replace of the following:
- Search: </wp:post_id>
- Replace: 000</wp:post_id>
- 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
- a. For the wp_em_event and wp_em_location tables (prefixes may vary), run these two queries:
- UPDATE `wp_em_locations` SET post_id=post_id*1000;
- UPDATE `wp_em_locations` SET post_id=post_id*1000;
- 3. Disable ALL plugins and theme on destination, including EM
- 4. Install Custom Post Type UI plugin and import this CPT setting and for Post Types
- {"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":""}}
- And this one for Taxonomies
- {"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"]}}
- 5. Make sure this file is included within your wp-content/plugins or wp-content/mu-plugins folder on your destination site.
- 6. Use the importer file to import events, locations and recurring events
- 7. Disable 'Custom Post Types UI' plugin.
- 8. Activate EM again.
- */
- /**
- * Assumes that the importer is importing post IDs that don't exist on this new system, or are the same between destination/source
- * @param unknown $post_id
- * @param unknown $post
- * @return unknown|boolean
- */
- function my_wp_import_existing_post_mod( $post_id, $post ){
- global $importing_post_ids, $wpdb;
- if( empty($importing_post_ids[$post['post_type']]) ){
- $importing_post_ids[$post['post_type']] = $wpdb->get_col($wpdb->prepare('SELECT ID FROM '.$wpdb->posts.' WHERE post_type=%s', $post['post_type']));
- }
- if( in_array($post['post_id'], $importing_post_ids[$post['post_type']]) ){
- return $post['post_id'];
- }
- return false;
- }
- add_filter('wp_import_existing_post', 'my_wp_import_existing_post_mod', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement