Skip to content

Instantly share code, notes, and snippets.

@jsit
Last active March 5, 2020 17:35
Show Gist options
  • Save jsit/98524a8ba4a97b9fd8db to your computer and use it in GitHub Desktop.
Save jsit/98524a8ba4a97b9fd8db to your computer and use it in GitHub Desktop.
Allow WP All Import to create events with Events Manager
// Create a proper EM_Event object in the database when an event-type post is
// imported with WP All import
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($post_id) {
if (class_exists(EM_Event)) {
$event_post = get_post($post_id);
// Only create a new event entry if the imported post is of type event and
// there is not an existing event for this post
$existing_event = em_get_event($event_post->ID, 'post_id');
if ($event_post->post_type == 'event' && empty($existing_event->event_id)) {
add_filter('em_event_can_manage', 'force_can_manage', 10, 1);
$event = new EM_Event();
$event->load_postdata($event_post);
$event->save();
remove_filter('em_event_can_manage', 'force_can_manage');
}
}
}
function force_can_manage($boolean) {
return true;
}
@alexnnnn
Copy link

alexnnnn commented Feb 21, 2018

Hi, Jay!
Great job, its work well!
But could you help me to change (or add) this snippet to work with EM_Location?
like this

  1. Create a new location entry if the imported post is of type event and location dosn't exist (create _location_id).
  2. Load 3 custom fields to Location post type (EM_Location):
    _location_name
    _location_address
    _location_country.
    Custom fields already exist when a event-type in WP All import.

@jsit
Copy link
Author

jsit commented Mar 5, 2020

@elito This should go in your theme's functions.php file.

@alexnnnn I'll have to look into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment