• Hi,
    So I am using this script in order to write an address (and lat/lng info) to the database. This is however not always working.
    Most of the times the record gets created in the mysql db, but sometimes it does not. Especially when using larger addresses/names.

    So, I have done A LOT of testing to see what is causing this. I did revert back to a twenty WP theme and disabled all other plugins with no luck.

    Any idea why this is not working properly? I already found out something goes wrong with the gmw_pt_update_location function. And because it especially goes wrong with larger addresses/names, it might have to do with the google maps api response time? Any suggestions are welcome. Thanks

    I am trying to add the address with the following code

    function gmw_update_post_type_post_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;
    		
    	//Add post Meta
    	add_post_meta($post_id, 'address', $_POST['address'], false);
    	
        //get the address from the custom field "address"
    	$addressarray = get_post_meta( $post_id, 'address', true );
    	$address = $addressarray[0];
    	//$address = $_POST['address'];
    
    	//varify that address exists. Otherwise abort the function.
    	if ( empty( $address ) )
    		return;
       
    	//include the update location file file
    	include_once( GMW_PT_PATH .'/includes/gmw-pt-update-location.php' );
      	
        //make sure the file included and the function exists
    	if ( !function_exists( 'gmw_pt_update_location' ) )
    		return;
       
        //Create the array that will pass to the function
    	$args = array(
    			'post_id' => $post_id, //Post Id of the post 
    			'address' => $address // the address we pull from the custom field above
    	);
    	
    	//Add location
    	gmw_pt_update_location( $args );
    }
    //execute the function whenever post type is being updated
    add_action( 'save_post_mpp-gallery', 'gmw_update_post_type_post_location', 13, 1 );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, I’m having exactly the same problem with update location and I’ve spent an age troubleshooting it / trying to define exactly what causes an address to populate successfully or not – no luck either, developer please can you let us know what might be causing this fault? Many thanks

    When I read through the forum before posting a Q, I saw @mav3000 may have had a similar problem before, and resolved it. @mav3000 would you mind sharing info about how you solved your prob to see if it could help us?
    https://www.ads-software.com/support/topic/gmw_pt_update_location-not-geolocating-address/?replies=4
    Thanks

    Thread Starter wzshop

    (@wzshop)

    Hi,
    Yes did a lot of debugging myself without any luck. Would love to hear any solution from @mav3000 or the developers.
    I basically ended up now with creating a loop for the gmw_pt_update_location function, chechking if the $post_id record exists in the DB and if not run the gmw_pt_update_location function again. Ive set a max counter of 30 times. Seems to be quite solid but obviously it’s not the desired solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘gmw_pt_update_location OR gmw_update_post_location not working properly.’ is closed to new replies.