Forums Forums Search & Filter Pro input field for post meta value search?

Tagged: 

  • This topic has 6 replies, 2 voices, and was last updated 8 years ago by Anonymous.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Anonymous
    #72415

    How do I create single input field like search form for post meta value search?

    For example, zip code search.
    There is a custom post type that have zip_min’ & ‘zip_max’ custom field.
    And I’d like to have users input their zip code and search posts that input zip code is in range of its zip_min and zip_max.

    I’m thinking to set meta_query in sf_edit_query_args() but I don’t know how to create input field for that.

    Trevor
    #72419

    I am not entirely sure what it is you are doing. In part that may be because ‘zip’ codes vary in format around the world and where I live they have mixed formats or alpha, spaces and numbers – making them very hard to create searches for.

    Anonymous
    #72462

    Sorry, It’s US zip code and always 5digit.
    So it’s numeric.

    Trevor
    #72860

    Have you tried using the Post Meta Form UI object, then set it to Range and Input Type Range - Number and set the meta keys as required for Start and End. Or did you try that already?

    Anonymous
    #72977

    Actually what I want is not that user select range of value and search single custom field.
    I want to have user input single number and search two custom fields see if number is in range of two.

    I tried this in sf_edit_query_args to catch search form value and set it to custom fields.

    $zip=$query_args['s'];
    unset($query_args['s']);
    $query_args['meta_query']=Array(Array('key'=>'zip_min','value'=>$zip,'compare'=>'<=','type'=>'NUMERIC,'),Array('key'=>'zip_max','value'=>$zip,'compare'=>'>=','type'=>'NUMERIC,'));

    So far it seems to to working but I’m not sure this is proper way.

    Trevor
    #73095

    Ah, I see. I tried to do something similar before but failed where you have succeeded. Kudos. Is this resolved for now?

    Anonymous
    #73377

    If you think this method is fine, I’ll go with it.
    So this is resolved.

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