Skip to content

Instantly share code, notes, and snippets.

@jsit
Last active March 5, 2020 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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;
}
@jsit
Copy link
Author

jsit commented Jun 8, 2015

This doesn't work on cron imports, for some reason; I'm looking into it.

@jsit
Copy link
Author

jsit commented Jun 8, 2015

This doesn't work on cron imports, if "Allow anonymous event submissions?" is set to "No" in Events Manager settings, due to the permissions check on line 632 of classes/em-event.php.

@jsit
Copy link
Author

jsit commented Jun 8, 2015

Added force_can_manage, which fixes problem with cron imports.

@jrwstevenson
Copy link

If I can get this working, it will really save my Bacon! I'm getting an HTTP Error 500 when I add this to my themes functions.php.

Any help will be greatly appreciated!

James

@jrwstevenson
Copy link

More specifically, the error appears when I click "Continue to Step 4"
image

@elito
Copy link

elito commented Dec 2, 2016

Hi,
i'm very interesting by this snippet, but where do i paste it ? In wpallimport function area or in theme functions.php ?

Thank's

@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