• 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 2 years, 10 months ago by geylang666.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter geylang666

    (@geylang666)

    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

    (@ninjew)

    Hello @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

    (@geylang666)

    @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

    (@geylang666)

    @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.