4

I can not seem to find anything regarding listing what categories were selected in the search query on the results page for Low Search.

Here's an example of my code on the search page:

                {exp:low_search:form collection="eat" search_mode="all" result_page="eat/sort" require_all="category"}
                <select name="category[]">
                    {exp:channel:categories channel="eat" style="linear" category_group="1"}
                        <option value="{category_id}">{category_name}</option>
                    {/exp:channel:categories}
                </select>

                <select name="category[]">
                    {exp:channel:categories channel="eat" style="linear" category_group="6"}
                        <option value="{category_id}">{category_name}</option>
                    {/exp:channel:categories}
                </select>
                <button type="submit">Search</button>
                {/exp:low_search:form}

And here's the results:

                <ul id="things-inner-list">

               {exp:low_search:results query="{segment_3}" status="not closed" limit="1" paginate="bottom"}
                  {if count == 1}
                    <p>
                      {if low_search_keywords}Searched for <strong>{low_search_keywords}</strong>.{/if}
                      Total results: <strong>{absolute_results}</strong>.
                    </p>
                  {/if}

                    <li>

                        <div class="things-item-left">
                            <img src="{eat_business_image}" />
                            <h2> <a href="{title_permalink='business/bar-and-grill}">{title}</a></h2>
                            <p>
                               {excerpt}
                            </p>
                        </div>
                        <div class="things-item-right">
                            <a class="map-it" href="{eat_business_map_url}" target="_blank">Map it</a>
                            <br />
                            {eat_business_phone}
                            <br />
                            <a href="{eat_business_web_url}" target="_blank">Website</a>
                        </div>

                    </li>

                  {paginate}
                    <p>Page {current_page} of {total_pages} pages {pagination_links}</p>
                  {/paginate}

                  {if no_results}
                    <p>
                      Sorry, your query did not return any results.
                    </p>
                  {/if}

                {/exp:low_search:results}

                </ul>

I am just looking to list what categories were selected on the search page, but I can't seem to get it and there's nothing in the documentation about it. I would also like to be able to have the option have the value selected on the results page, as I have the search form on the results page as well. Is this possible?

1 Answer 1

1

You can use the variable {low_search_category} in your Form, Filters and Results tags, as long as you feed it the query="" parameter (when encoding the URI). This will output a pipe-separated list of category IDs that were selected in the search form.

To "remember" which categories were selected in your Form tag, add the query="" parameter to it, and then use the Special Conditionals to add the selected attribute to the <option>:

<option value="{category_id}"{if category_id IN ({low_search_category}) selected="selected"{/if}>
    {category_name}
</option>

To show a list of selected categories elsewhere on the page, you're probably best off using the Filters or Results tag with a {exp:channel:categories} tag to output the category names.

{if '{low_search_category}' != ''}
    You selected these categories:
    {exp:channel:categories show="{low_search_category}" channel="eat" style="linear"}
        {category_name}
    {/exp:channel:categories}
{/if}
10
  • Sweet, thanks for the fast reply, Low. I'll take a look and get back to you with my results :)
    – Cogweb
    Commented May 21, 2013 at 14:34
  • Low, here's my code for the option. It doesn't seem to be working, no 'selected' appears in the option. Argh, added it to your post instead of mine. Sorry :)
    – Cogweb
    Commented May 21, 2013 at 14:54
  • Almost there. Instead of query="", you need to actually add a value. So query="{segment_3}" in your case.
    – Low
    Commented May 21, 2013 at 15:02
  • Ok! Those are good to go. Now... <div>{exp:low_search:results query="{segment_3}" status="not closed" limit="1" paginate="bottom"} {if low_search_category} You selected these categories: {exp:channel:categories show="{low_search_category}" channel="eat" style="linear"} {category_name} {/exp:channel:categories} {/if} This isn't working. It returns a blank result. :( Thanks for all your help!
    – Cogweb
    Commented May 21, 2013 at 15:05
  • What's your LS version?
    – Low
    Commented May 21, 2013 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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