Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Created June 10, 2015 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thierrypigot/54bdf9e1e2a6ed1add10 to your computer and use it in GitHub Desktop.
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"
/**
* 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