Support

Account

Home Forums ACF PRO Query posts by ACF google maps value Reply To: Query posts by ACF google maps value

  • The google map field stores a serialized array that looks something like this

    
    a:3:{s:7:"address";s:42:"XXXX XXXXXX Road, Pxxxx, NY, United States";s:3:"lat";s:9:"42.979788";s:3:"lng";s:18:"-75.29690099999999";}
    

    It would be extremely difficult to list all of the cities. To do this you would need to

    1. Get all of the posts
    2. Loop through the posts and get the field value
    3. Extract the city from the first array element
    4. Store the unique cities in an array
    5. Sort the array

    Searching for a specific city would require a LIKE query similar to doing a query on a relationship field https://www.advancedcustomfields.com/resources/querying-relationship-fields/

    The easiest solution would be to provide a city field that can be more easily searched.

    The next best solution would be to extract the city from the map field when the post is saved and then store it in a different postmeta field to search on that. There is an example of the basics of doing this in this topic https://support.advancedcustomfields.com/forums/topic/update-post_meta-with-acf-date-value/. It does not deal with map fields and you’d have to figure out how to extract the city from it. To be honest I’m not sure how that could be done exactly.