Last active
March 5, 2020 17:35
-
-
Save jsit/98524a8ba4a97b9fd8db to your computer and use it in GitHub Desktop.
Allow WP All Import to create events with Events Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@elito This should go in your theme's
functions.php
file.@alexnnnn I'll have to look into that.