Created
November 26, 2018 21:17
-
-
Save Fitoussi/62ac290123186de151b28c42ce003908 to your computer and use it in GitHub Desktop.
Sync the location from Events Manager plugin with GEO my WP plugin.
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
/* | |
This example integrates GEO my WP and Events Manager plugin. | |
The script will update GEO my WP database table with the location | |
entered in the Event form from the front-end and back-end. | |
Note that when using GEO my WP together with Event Manager plugin | |
you should disable the GMW Location section for the Events Edit Post page ( in the back-end ) | |
since The usage of Google maps API by the to plugin causes a conflict. | |
*/ | |
//rename your custom function as you wish ( or leave it as is ). | |
function gmw_update_event_manager_location( $post_id ) { | |
// verify that even is being updated. | |
if ( empty( $_POST['action'] ) || 'event_save' !== $_POST['action'] ) { | |
return; | |
} | |
// Verify that the updater function exists. | |
if ( function_exists( 'gmw_update_post_location' ) ) { | |
// Pass the submitted address field of the Event Manager plugin as an array. | |
$address = array( | |
'street' => $_POST['location_address'], | |
'city' => $_POST['location_town'], | |
'state' => $_POST['location_state'], | |
'zipcode' => $_POST['location_postcode'], | |
'country' => $_POST['location_country'], | |
); | |
//run the updater | |
gmw_update_post_location( $post_id, $address ); | |
} | |
} | |
//execute the function whenever post type is being updated | |
add_action( 'save_post_event', 'gmw_update_event_manager_location' ); |
Hello,
Thank you for this code.
The problem is that if an address field is left blank in the event form, the updater does not delete the data entered before. So the marker keeps showing up on the map, even if the event has no address but a URL location instead. Meaning : in case of mistake, the user must delete the event to delete the marker on the map.
Otherwise GeoMyWP works very well with Events Manager. Thank you very much for sharing this great plugin.
Best regards
Edit : No it does really not work when the event has a URL location. Sometimes a random address is attributed to a new event with blank fields address. Strange...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this code!
I have another idea ... let's say GEO my WP already has an "address" from post field "address"...
But now, how to grab the fields (country_name, city, formatted_address) from GmW and insert to the taxonomies "city" and 'country' .... for current custom post type "event" during this post update (add_action( 'save_post_event'....)?
Could you help me?