All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Low Search - Category Filter on Search results page

Ashley 25 Mar 2013 21:04 question, complete

I am searching through a category filter. How do I display which category was searched on the results page? Something like this:

You searched for{low_search_keywords} within {category_name}

Also, how do I control the url of the page so it doesnt have all of the numbers? I would ilke it to be mydomain.com/search/results/search...term...here

Replies

  1. Low 25 Mar 2013 21:26

    To get which categories were selected in the form, you can use the variable {low_search_category}. This will give you a pipe-separated list of category IDs, which you could use for the native channel:categories tag. So, for example:

    {exp:low_search:filters query="{segment_3}"} 
    <p>
    You searched for {low_search_keywords} within
    {exp:channel:categories channel="news" style="linear" show="{low_search_category}"}
    {category_name}
    {/exp:channel:categories}
    </p>
    {/exp:low_search:filters}


    About the encoded query; that is a current necessity within EE. EE doesn't allow GET variables by default and the characters allowed in the URI are limited as well. Try adding a ; to any EE URI, and you'll see a 'The URI you submitted has disallowed characters' error. To work around this limitation, the search query (including keywords, category info and all other data you might add to the Form) is encoded in a URI-safe way.

  2. Ashley 25 Mar 2013 22:11

    Thanks, the category is still not showing up on the results page with this code:

    {exp:low_search:filters query="{segment_3}"}

    You searched for {low_search_keywords} within
    {exp:channel:categories style="linear" show="{low_search_category}" channel="business-listing"}
    {category_name}
    {/exp:channel:categories}


    {/exp:low_search:filters}

    Also, could you provide a little bit more specific instruction on how to control the results url? I am still not sure how to work around this limitation, or if it is possible?

  3. Low 25 Mar 2013 22:18

    What does your Low Search Form look like? You can paste large chunks of code in http://pastie.org so it remains readable.

    Short answer for a readable URI: that's currently not officially supported. I know devot:ee has used a custom form that uses GET, and then uses Mo Variables to feed the GET variables directly into the Low Search Results tag. But since GET vars aren't officially supported by EE itself, neither are they in Low Search.

  4. Ashley 25 Mar 2013 22:48

    Ok, thanks on the URI info.

    My current search form looks like this:
    http://pastie.org/private/ifcjvmg9nwg...

  5. Low 25 Mar 2013 22:53

    Try changing the opening <select>-tag to this:

    <select name="category"> 
    <option value="">Choose Location</option>
    ...
    </select>

  6. Ashley 25 Mar 2013 22:59

    That worked, thank you!

  7. Ashley 26 Mar 2013 22:51

    How do I make the category dropdown a required field?

  8. Low 27 Mar 2013 09:07

    Add required="category" to the Form tag.

  9. Ashley 4 Apr 2013 16:25

    Ok, continuing on this project and ran into another question. On the search results page, I would like to keep the category selected that the user selected on their original search. So for example, I search for "Movie Theatre" in the (category) Omaha and dont come up with the results I am expecting. On the results page I would like to perform another search without choosing or changing the location (which in our case is the category dropdown.) I have tried the following code but the value="" ends up blank.

    http://pastie.org/7316231

  10. Low 5 Apr 2013 06:29

    You should get rid of all the Filters tags if they are inside a Form tag. Instead, add the query="" parameter to the Form tag, so you can use any of the variables available in the Filters tag in the Form tag as well. In fact, both tags are the same, but the Form tag wraps a form around the tagdata.

    Take a look at the advanced example. In the middle, you can see the Categories dropdown being generated, along with a conditional to remember which one was selected.

  11. Ashley 8 Apr 2013 21:51

    Another question on this project - (thanks for your help, everything you have helped us with is working like a charm.)

    We have some sidebar content that we would like to filter by the same category that the user chose in their search.

    Here is the code we are trying to put category="{category_id}" in the channel entries, but it is not working (nothing is displaying.)

    http://pastie.org/7376602

  12. Low 9 Apr 2013 08:43

    You can't just use any amount of tags inside another tag's parameter. You need to wrap them around each other. To what tag does the category="" parameter belong? Wrap the Filters tag around it and just use {low_search_category} inside the parameter.

  13. Ashley 9 Apr 2013 19:31

    The category parameter belongs to a playa:parents tag, and Im thinking this is why its not working. Is there any way I can filter these playa parent results based on the category chosen when the search was performed?

    I tried this: {exp:playa:parents channel="listings" status="Super Enhanced|Enhanced|Basic" {exp:low_search:filters query="{segment_3}"}category="{low_search_category} "{/exp:low_search:filters} limit="6"}

  14. Low 9 Apr 2013 19:35

    No, again you're putting tags inside another's opening tag. Try this:

    {exp:low_search:filters query="{segment_3}"} 
    {exp:playa:parents category="{low_search_category}" ... }
    ...
    {/exp:playa:parents}
    {/exp:low_search:filters}

  15. Ashley 9 Apr 2013 19:55

    This didnt work either - is there any way I could use your Low Seg2Cat module to pull the category id out of segment_3?

    I was not able to customize the search results url, so our results url is still the original long version.

  16. Low 9 Apr 2013 19:56

    What's the rest of your template. Also, what's the encoded query in the URI?

  17. Ashley 9 Apr 2013 20:21

    This is the part of the sidebar that we need to filter by category:
    http://pastie.org/private/ecj4zl42ghf...

    Throughout the rest of the site we are using Low Seg2Cat to filter the results that are displayed on this same code in the sidebar, however it doesnt work on the results page because we are unable to include the category in the url.

    I don't know what the encoded query is in the URI, our search form is searching for keywords and a category select dropdown.

  18. Low 9 Apr 2013 20:28

    Seg2Cat won't work with the search URI.

    Try putting the main channel:entries tag inside a low_search:filters tag. So:

    {exp:low_search:filters query="{segment_3}"} 
    {exp:channel:entries channel="daily-deals" orderby="random" dynamic="no"}
    ...rest of your code...
    {/exp:channel:entries}
    {/exp:low_search:filters}


    That way all {low_search_...} variables should be parsed in time for the other tags to use them, including the {low_search_category} variable in the Playa tags.

  19. Ashley 9 Apr 2013 20:46

    This worked, thank you. One more thing, do you have any idea why the limit=6 is not working in this code?

    Thanks again.

  20. Low 9 Apr 2013 20:56

    Not sure. Have you asked Pixel & Tonic support?

  21. Ashley 11 Apr 2013 03:53

    I have asked them and am working with them on it.

    Another question: I have another category group that I would like to appear in the search results. Is this possible? It wouldnt be something that would show up in a filter, rather if there were a word (i.e. restaurant in ohio) the category Restaurant would show up in the search results.

    Thanks,

  22. Low 11 Apr 2013 06:38

    Only with a bit of a workaround: http://gotolow.com/blog/searching-non...