• Hi.

    I have an input search field (city, state, zip) that does a meta_query against an address custom field.

    My question is if you can compare strings where if any words match between the two strings it will return true.

    In the meta_query args I set the compare arg to “LIKE”. It sort of works.

    If someone types in just “Connecticut” it pulls posts with Connecticut in the custom field. However, if someone types in “Connecticut USA” it pulls nothing.

    I want to make the search as broad as possible so as long as the person has one matching word in the input, it will return true.

    Is something like this possible?

Viewing 1 replies (of 1 total)
  • Thread Starter working-together

    (@working-together)

    I had the idea to try to use explode() to make my string into an array of values and then use the IN operator. It doesn’t seem to work at all and I wonder if it is because the array has keys.

    $city_state_zip = explode(” “, $city_state_zip);
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘My_key’,
    ‘value’ => $city_state_zip, //not sure if this would excepts this sort of array.
    ‘compare’ => ‘IN’
    )

    Not sure if this sort of thing is possible.

Viewing 1 replies (of 1 total)
  • The topic ‘Compare strings with meta_query’ is closed to new replies.