I am going to split up my following question in two sections and make it more neutral, so people can look it up and find it if they have the same question, rather than making it too specific ...

I am trying to build a search for something location based and want people to be able to search either ZIP, Town, County or State in one single field.

My custom post_type has multiple meta_keys which I want to search for with one single search field. As example:

post_type = location_type | meta_key = zip | meta_key = town | meta_key = county | meta_key = state |

Now, what I want to do is, I want to search if EITHER or MORE of these fields contains the search value and want to query all applying posts, displaying the custom-posts meta_key value for Profession meta_key = profession.


You can use meta query as give below:

$args = array(
    'post_type'         => 'location_type',
    'posts_per_page'    => 10,
    'post_status'       => 'publish',
    'meta_query' => array(
        'relation' => 'OR',
            'zip'     => 'zip-value'
            'town'     => 'town-value'
  • Thank you so far. At the moment, I am stuck at making it possible for the user to search for the meta_value. They are not supposed to to search for the title or content, but only the meta_values. Never had to alter the search before, kinda giving me a headache right now ;) Thanks so far! – marvinpoo May 7 '18 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.