Created
June 10, 2015 18:47
-
-
Save thierrypigot/54bdf9e1e2a6ed1add10 to your computer and use it in GitHub Desktop.
Sauvegarde les lat / lng en postmeta. Utilise le champ ACF GoogleMaps de base, qui a pour nom "localisation"
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
/** | |
* Save _lat _lng | |
* | |
**/ | |
add_action( 'save_post', 'stl_store_meta_save' ); | |
function stl_store_meta_save( $post_id ) | |
{ | |
global $wpdb; | |
$table = $wpdb->prefix .'geodatastore'; | |
if ( isset( $_POST['post_type'] ) && $_POST['post_type'] != 'store' ) | |
return; | |
if( $localisation = get_post_meta( $post_id, 'localisation', true ) ) | |
{ | |
if( isset( $localisation['lat'] ) && isset( $localisation['lng'] ) ) | |
{ | |
add_post_meta( $post_id, '_lat', sanitize_text_field( $localisation['lat'] ), true ) || update_post_meta( $post_id, '_lat', sanitize_text_field( $localisation['lat'] ) ); | |
add_post_meta( $post_id, '_lng', sanitize_text_field( $localisation['lng'] ), true ) || update_post_meta( $post_id, '_lng', sanitize_text_field( $localisation['lng'] ) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment