GEO my WP Support

Use this forum for technical support and general questions related to GEO my WP plugin and its core add-ons only. For technical support and general questions related to any of the premium extensions please open a new premium support ticket.

[Not resolved]Auto-populating the Location Field

Home Forums Support Auto-populating the Location Field

Tagged: ,

This topic contains 9 replies, has 4 voices, and was last updated by  Eyal Fitoussi 2 months, 3 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #57069

    waloob73
    Participant

    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.

    #57087

    Eyal Fitoussi
    Keymaster

    Hi,

    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.

    #57088

    waloob73
    Participant

    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.

    #57097

    Eyal Fitoussi
    Keymaster

    Sure,

    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.

    #57104

    waloob73
    Participant

    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?

    #57116

    Eyal Fitoussi
    Keymaster

    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.

    #59094

    ahesse
    Participant

    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!

    #59139

    Eyal Fitoussi
    Keymaster

    Hello @ahesse,

    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:

    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:

    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.

    #59284

    V8200T5
    Participant

    Hi, we are also trying to import locations via CSV files and WP All Import. We have the address, latitude, and longitude as well as the Google Maps listing url. Was there some update regarding saving the locations in the database?

    #59293

    Eyal Fitoussi
    Keymaster

    Hello @v8200t5,

    Since your data contains the address and the coordinates the importing process should be easier:

    1. Using WP All Import, import the data from the CSV file while saving the address and coordinates into custom fields of your choice.

    2. Navigate to the dashboard -> GEO my WP -> Import/Export -> Posts Locator tab. In the “Post Custom Fields” section of this tab, click the “Set Custom Fields” and choose the address and coordinates fields that you used when importing the data. Then click “Import” to import the data from the custom fields into GEO my WP database table.

    Let me know if this helps.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.