April 1, 2018 at 6:49 am #57069
I need to populate the Location field of a custom post type when importing a bunch of posts from a CSV. I’m happy for it to select the closest match as the options will be town/city names, e.g. London, Manchester, etc.
How can I do this? At the moment you have to manually edit each post and select an option from the auto-suggest, I need it instead to make a best guess based on data that’s placed in that field during import.April 2, 2018 at 2:09 pm #57087
What kind of location data is included in the CSV file? An address field only?
Unless you can include the coordinates as well, I am afraid there isn’t a “simple” solution for bulk geocoding. It is possible, but requires custom coding.
Please see this reply for more information.April 2, 2018 at 10:10 pm #57088
The column contains the city name only, e.g. ‘London’
I’m using WP All Import, which allows me to run a php function at the point of creating the post, so if you can point me to the function that does the lat/long lookup and returns the coordinates I should be able to use that to populate those fields.April 4, 2018 at 6:54 pm #57097
The function is gmw_update_post_location() and can be found in geo-my-wp/plugins/posts-locator/includes/gmw-posts-locator-functions.php.
One thing you need to have in your script is a delay of about 3 seconds between each imported post. You do so to prevent the abuse of Google Maps API ( when geocoding addresses ), which can results in the banning of your IP address.
You also should not geocode more than 2000 address per 24 hours. This is also one of Google Map API restrictions.
I hope this helps.April 7, 2018 at 12:51 am #57104
Is it possible to set a default location (e.g. ‘United Kingdom’) so that all posts created at least have this location set to start with, then they can be edited if required to be more specific?April 7, 2018 at 12:19 pm #57116
Not out of the box, but it should be possible with a custom function.
You need to execute the custom function on wordpress’ save_post action, and check if this is a new post being created. And if so, use the gmw_pt_update_location() function to create the default location as you wish.
I hope this helps.April 8, 2019 at 10:05 pm #59094
Good to know that others are dealing with the exact same problem. We’re also importing csv data into CPT via the All-Import plugin, very common.
Eyal, any updates on this issue in the last year? New features of Geo-My-WP, or changes at Google Maps.
What if we had bulk longitude and latitude data?
How are the corresponding fields of Geo-My-WP exposed during the import process, so that they can mapped?
Thanks!April 18, 2019 at 5:02 pm #59139
Unfortunately, I haven’t got to work much on the importing part of GEO my WP. I have been working on other improvements, bugs fix, and features that have been on my to-do list for a very long time.
There are a couple of functions that you can use to insert new locations into GEO my WP while importing data.
One function is:1gmw_update_location_data( $location_data );
This function will import a location when all the required data is provided via the $location_data array. The required data is the object_type ( post ), object_id ( post ID ), address, formatted_address, latitude, and longitude. You can find the default location values in geo-my-wp/includes/class-gmw-location.php in the deafult_values() function. The more location data provided the better, but you need at least the values mentioned above.
If the coordinates or address fields are missing in the file you import, then you will need to use the function:1gmw_update_post_location( $post_id, $location );
This function will geocode an address or reverse geocode coordinates and will save the location in the database. You can find the function in geo-my-wp/plugins/posts-locator/includes/gmw-posts-locator-functions.php.
Now, you need to find a hook in the WP All import plugin that fires after each post that is being imported and use that hook to fire one of the functions mentioned above.
I hope this helps.
You must be logged in to reply to this topic.