Title: Post Location Function Not Working
Last modified: January 6, 2022

---

# Post Location Function Not Working

 *  [geylang666](https://wordpress.org/support/users/geylang666/)
 * (@geylang666)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/post-location-function-not-working/)
 * Hi team,
 * We are using the gmw_update_post_location function to update GMW location of 
   posts as per instructed.
 * However, it is not working. Can you help check out code?
    Thanks.
 *     ```
       function gmw_update_post_type_model_location(  $post_id ) {
   
       	// Return if it's a post revision.
       	if ( false !== wp_is_post_revision( $post_id ) ) {
       		return;
       	}
   
       	// check autosave.
       	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
       		return;
       	}
   
       	// check if user can edit post.
       	if ( ! current_user_can( 'edit_post', $post_id ) ) {
       		return;
       	}
   
       	// get the address from the custom field "address".
       	$map_location = get_post_meta( $post_id, 'map_location', true );
       	$location = get_post_meta( $post_id, 'location', true );
       	$area = get_post_meta( $post_id, 'area', true );
       	$base_city = get_post_meta( $post_id, 'base_city', true );
       	If ($map_location != '') {
       	    $address = $map_location;
       	} else {
       	    $address = $location.', '.$area.', '.$base_city;
       	}
   
       	// varify that address exists.
       	if ( empty( $address ) ) {
       		return;
       	};
   
       	// verify the updater function.
       	if ( ! function_exists( 'gmw_update_post_location' ) ) {
       		return;
       	}
   
       	//run the udpate location function
       	gmw_update_post_location( $post_id, $address );
   
       }
       //execute the function whenever post type is being updated
       add_action( 'save_post_model', 'gmw_update_post_type_model_location' );
       add_action( 'acf/save_post', 'gmw_update_post_type_model_location' );
       ```
   
    -  This topic was modified 4 years, 5 months ago by [geylang666](https://wordpress.org/support/users/geylang666/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [geylang666](https://wordpress.org/support/users/geylang666/)
 * (@geylang666)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/post-location-function-not-working/#post-15226063)
 * We tested a lot, and it shows that even if we want to execute the following
 * gmw_update_post_location( $post_id, ‘test address’ );
 * It also does not work.
 *  Plugin Author [Eyal Fitoussi](https://wordpress.org/support/users/ninjew/)
 * (@ninjew)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/post-location-function-not-working/#post-15226115)
 * Hello [@geylang666](https://wordpress.org/support/users/geylang666/),
 * You should verify that your Google Maps Server API key is working properly.
 * If you haven’t done so already, navigate to the dashboard -> GEO my WP -> Tools-
   > API Testing, and click to test your Maps API.
 * If the API key testing fails, the function that you are trying to use won’t work.
   So you’ll have to correct your API key.
 * Let me know if this helps.
 *  Thread Starter [geylang666](https://wordpress.org/support/users/geylang666/)
 * (@geylang666)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/post-location-function-not-working/#post-15226555)
 * [@ninjew](https://wordpress.org/support/users/ninjew/) Thank you for quick response!
 * Just to confirm: we actually chose Leaflet as the “Maps Provider” – would that
   require to verify Google API as well?
 * Thanks!
 *  Thread Starter [geylang666](https://wordpress.org/support/users/geylang666/)
 * (@geylang666)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/post-location-function-not-working/#post-15227010)
 * [@ninjew](https://wordpress.org/support/users/ninjew/) some follow-up:
    We fixed
   the Google API Keys and now it works with Google Map. However, the Leaflet Map(
   our preferred option) still does not work. Did the Leaflet option stop providing
   the service? Thanks. BR, Gey

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Post Location Function Not Working’ is closed to new replies.

 * ![](https://ps.w.org/geo-my-wp/assets/icon-256x256.gif?rev=2803407)
 * [GEO my WP](https://wordpress.org/plugins/geo-my-wp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/geo-my-wp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/geo-my-wp/)
 * [Active Topics](https://wordpress.org/support/plugin/geo-my-wp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/geo-my-wp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/geo-my-wp/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [geylang666](https://wordpress.org/support/users/geylang666/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/post-location-function-not-working/#post-15227010)
 * Status: not resolved