Home Forums General Issues perform a meta query on google maps array


perform a meta query on google maps array

  • I’m attepting to do a meta query on a google maps field. The map field is called “full address”.
    Here is my start which works.

    if(isset($_GET[‘city’])) {
    $city = sanitize_text_field( $_GET[‘city’] );
    $meta_query[] = array(
    ‘key’ => ‘full_address’,
    ‘value’ => $city,
    ‘compare’ => ‘LIKE’

    The problem is that if I’m querying a city “Boise” but there is an address in my db that is: 123 boise road, medford, oregon.

    it shows up as well.

    So I’d like to instead of using the whole field as the key for the meta query to be able to use ‘full_address:city’. Is this possible?

  • The field is stored as a serialized array. Put double quotes around the value to get the exact match.

    value’ => '"'.$city.'"',
  • Thanks John! Can you explain why this works? Or point me in a research direction?

  • The data in the database is serialized

    For example, an array with Boise in the city might look like this

    a:2:{s:4:"city";s:5:"Boise";s:7:"address";s:15:"123 Main Street";}

    By adding the quotes around the value we’re looking for matches this city

    On the other hand, with Boise in the street it might look something like

    a:2:{s:4:"city";s:13:"Somewheretown";s:7:"address";s:16:"123 Boise Street";}

    and it does not match because there are no quotes around Boise in the DB value.

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

You must be logged in to reply to this topic.