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
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.