Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    The only way to do that is to first bulk geocode them through a third party site, and then import them in phpMyAdmin. The steps are described in this post https://wordpress.org/support/topic/csv-upload-1?replies=15.

    Thread Starter seforoth

    (@seforoth)

    Hi Tijmen,

    Thank you very much on the info!

    However, I couldn’t wait so I jerry-rigged something yesterday 😉 Here is the code if anyone else is interested.

    <?php
    if ( isset( $_POST['update_all_entries'] ) ) {
    		global $wpdb;
    
    		$stores = $wpdb->get_results( "SELECT * FROM $wpdb->wpsl_stores" );
    
    		foreach ( $stores as $store ) {
    			$address = urlencode($store->address.','.$store->address2.','.$store->city.','.$store->state.','.$store->zip.','.$store->country);
    			$url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address={$address}";
    			$data = file_get_contents( $url );
    			$data = json_decode( $data );
    
    			$lat = $data->results[0]->geometry->location->lat;
    			$lng = $data->results[0]->geometry->location->lng;
    
    			$result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->wpsl_stores SET lat = %f, lng = %f WHERE wpsl_id = %d", $lat, $lng, $store->wpsl_id ) );
    			sleep(2);
    		}
    	}
        ?>
                        <form method="post" action="http://homyped.dev/wp-admin/admin.php?page=wpsl_settings" accept-charset="utf-8">
    					<input type="submit" id="update-all-entries" name="update_all_entries" value="UPDATE ALL ENTIRES">
    					</form>

    I’ve added this code to the map-settings.php as it made the most sense to have it there.

    Kind Regards,

    Sef

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

The topic ‘Bulk Update for Lat Long’ is closed to new replies.