0

Scenario:

WHEN User searches for a random term lets say pepe on my initial search page.

THEN User sees the results page with lots of results.

THEN User wants to filter those results by Clicking in any of the Categories filter

THEN User sees the results of pepe for the specific category that he selected.

Problem

I'm able to do the first search and display all results independent of category. When I try to run a 2nd search on the result's page and pass the filter category I don't know how to make the system remember the first query or pass the value of search:title.

How can I achieve that?

Initial Search Page

{exp:low_search:form
  form_attribute="search-form"
  result_page="search"
  collection="article"
  search_mode="all"
}
  <fieldset>
    <label for="keywords">Search</label>
    <input type="search" name="search:title"/>
    <button type="submit">Search</button>
  </fieldset>
{/exp:low_search:form}

Results Page (UPDATED WITH WORKING CODE)

    <!-- Category filter-->


     {exp:low_search:form
            form_attribute="search-form"
            result_page="search"
            collection="article"
            search_mode="all"
            remember="search:title"
            query="{segment_2}"
}

<fieldset>
    {exp:channel:categories parent_only="yes" style="linear"}
        <button  name="category" value="{category_id}">{category_name}</button>
    {/exp:channel:categories}
</fieldset>

{/exp:low_search:form}

<!-- Search Results-->
{exp:low_search:results
    limit="10"
    query="{segment_2}"
    collection="article|food"
    status="open"
}
  {if count ==  1}<ol>{/if}
    <li><a href="{comment_url_title_auto_path}">{title}</a></li>
  {if count == total_results}</ol>{/if}
  {if no_results}No search results{/if}
{/exp:low_search:results}
1

Use the remember="" parameter on the second Form tag.

Set to the names of the parameters you want to pass through to the next search without having input fields for them in the form.

So, instead of having the hidden input field in the second form, use remember="search:title".


Additionally, there's a couple of things you can improve:

  • Instead of using search:title (the Field Search filter), try using keywords (the Keywords filter). This will increase performance and is the preferred filter for free text searches.
  • Don't add any filter parameters (like collection and search_mode) to your Form tag; they have no effect there. Add them to the Results tag instead. Also search_mode has been superseded by keywords:mode in Low Search v4.
| improve this answer | |
  • I've added the remember="search:title" to the tag and amended my code sample on the main post, but it still doesn't seem to work. – Jonathan Thurft Oct 21 '15 at 13:04
  • 1
    Make sure the query="" param is set, too. – Low Oct 21 '15 at 13:05

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.