Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sauvegarde les lat / lng en postmeta. Utilise le champ ACF GoogleMaps de base, qui a pour nom "localisation"
/**
* 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
You can’t perform that action at this time.