Support » Plugin: Relevanssi - A Better Search » searchform with a location field

  • Hello,

    First thanks for this great plugin, way better than the default WP search.

    I’m building a directory website for one of my clients, and he would like to have a searchform with 2 fields : one for the “business name or category” and one for the location (kind of like yellowpages.com).

    Right now, I have the companies’s address in a custom field. Searching this forum, I understood that the premium version makes available the &customfield_key and &customfield_value to filter the search. But before buying the premium, I have one question : if I input a city like “paris” in the location field, will it returns results that have a full address in the custom field, like “street test zipcode Paris” ? or only those which have only “paris” in the custom field ?

    I hope I made myself clear, and hope this can be answered easily

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Mikko Saari

    (@msaari)

    It will return any posts where the custom field has word Paris in it. It’s a wild card search, so it’ll match anything that has “paris” in it somewhere.

    Thread Starter Remy Perona

    (@tabrisrp)

    Great, one problem goes away, thanks !

    Now one more thing to go further : I want to be able to filter the search results with some checkboxes populated with custom taxonomies.

    I could see in the KB that we can search for multiple taxonomies at the same time like this

    ?s=query&taxonomy=director|actor&term=Scorsese|De+Niro

    but, can we also search for multiple terms in the same taxonomy ? for example :
    ?s=query&taxonomy=director|actor&term=Scorsese,Spielberg,Lucas|De+Niro

    Plugin Author Mikko Saari

    (@msaari)

    I haven’t tried it, but I believe this should work:

    ?s=query&taxonomy=director|director|director|actor&term=Scorsese|Spielberg|Lucas|De+Niro

    Plugin Author Mikko Saari

    (@msaari)

    In future versions, separating the values with commas will work as well, I’ll fix that.

    Thread Starter Remy Perona

    (@tabrisrp)

    Ok now, how can I make this work with a form submit ? since the GET request looks like
    ?s=query&director=Scorsese&director=Spielberg&director=Lucas&actor=De+Niro

    I guess relevanssi won’t understand and only process the first part

    Or should I rely on query_posts to filter with the taxonomies with the GET values ? I don’t know if it’s possible in a search results page.

    Thread Starter Remy Perona

    (@tabrisrp)

    Reading the FAQ, it looks like query_posts and relevanssi don’t work together.

    So how can I filter my results ? Should I use relevanssi_do_query() or the relevanssi_where hook ?

    Plugin Author Mikko Saari

    (@msaari)

    Hmm, yeah, it’s going to be tricky to do a form that works… This feature was requested by somebody, I wonder how they did it. I think they might’ve used JavaScript to modify the query. I’m not sure, as I’m not much of an expert in all things JavaScript.

    Thread Starter Remy Perona

    (@tabrisrp)

    Well I got it to work with some jQuery (creating a array with the submitted form values, and then looping in it to create the search string for relevanssi).

    Now, I’m having some trouble with the customfield_key and customfield_value which doesn’t look like to be working

    for a query string like this
    ?s=businessname&customfield_value=marseille&customfield_key=address

    I’m getting results with “businessname” with a address customfield value of “paris” instead of only the one with “marseille” as address customfield

    Am I missing something/doing something wrong here ? I’m on the premium version btw

    Plugin Author Mikko Saari

    (@msaari)

    I tried creating two posts with the word “businessname” and the custom field “address”, one with “paris” and the other with “marseille”. It works just as expected.

    Let’s continue this with email, you can contact me at mikko @ mikkosaari.fi. Hopefully we can work this one out.

    Did you guys resolve this? I have a similar need:
    I need a search form with two fields, “what” and “where”, and my client wants to be able to write several terms in each. Is that doable? I’d rather avoid javaScript if that’s possible.

    Thread Starter Remy Perona

    (@tabrisrp)

    Well as I said, I was able to make it work, but javascript was necessary to transform the query string, and my code was quite ugly and specific for my website. In the end we went for another solution for the user input.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘searchform with a location field’ is closed to new replies.