Low Search form with select dropdowns only
Hi there,
Please can you tell me where I am going wrong or if it is even possible.
I want to be able to search from 4 drop down selects, populated from 4 different category groups. My code is below but each time it returns all results. I am not using a keyword input at all in this form. Is that an issue?
Search page:
{exp:low_search:form query="{segment_3}" search_mode="all" result_page="careers/results" collection="careers"}
<fieldset>
{if error_message != ''}
<p class="error">{error_message}</p>
{/if}
<select name="location">
<option value="">-- Location --</option>
{exp:channel:categories channel="careers" style="linear" category_group="4"}
<option value="{category_id}"{if category_id IN ({low_search_category})} selected="selected"{/if}>
{category_name}
</option>
{/exp:channel:categories}
</select>
<select name="type">
<option value="">-- Contract Type --</option>
{exp:channel:categories channel="careers" style="linear" category_group="5"}
<option value="{category_id}"{if category_id IN ({low_search_category})} selected="selected"{/if}>
{category_name}
</option>
{/exp:channel:categories}
</select>
<select name="term">
<option value="">-- Contract Term --</option>
{exp:channel:categories channel="careers" style="linear" category_group="6"}
<option value="{category_id}"{if category_id IN ({low_search_category})} selected="selected"{/if}>
{category_name}
</option>
{/exp:channel:categories}
</select>
<select name="salary">
<option value="">-- Salary Range --</option>
{exp:channel:categories channel="careers" style="linear" category_group="7"}
<option value="{category_id}"{if category_id IN ({low_search_category})} selected="selected"{/if}>
{category_name}
</option>
{/exp:channel:categories}
</select>
<button type="submit">Search</button>
</fieldset>
{/exp:low_search:form}
Results Page:
{exp:low_search:keywords query="{segment_3}"}
{exp:low_search:results query="{segment_3}" limit="10" collection="careers"}
{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}
Many thanks in advance.
Replies
Low 24 Jul 2013 10:39
You're filtering by category, and you need to make sure Low Search knows. The name="" attributes in your select-elements need to reflect that. So, for each of your select elements, use name="category[]". The square brackets are necessary because you're targeting multiple categories here.
On top of that, I recon you'd want the selection to be inclusive, ie. results must match *all* selected categories. So instead of location OR type OR term OR salary, you'd want location AND type AND term AND salary.
In EE parameter syntax, that's the difference between category="1|2|3|4" and category="1&2&3&4". Low Search will assume the former for any multiple valued input field (like the 4 combined select elements are in your case). If you add require_all="category" to the Form or Results tag, the latter will be used, so you only get results for entries that have all selected categories assigned to it.
The search_mode="all" parameter is only needed for keyword searches and can be removed.
Mark 24 Jul 2013 11:19
Thanks for this, it did the trick.
Is there a way to get the select values into the keywords tag?
So on the results page I could say your search for "XXXX, XXXX, XXXX" returned X results?
Low 24 Jul 2013 11:33
You could use this inside a Results or Filters tag:
The (native) {absolute_results} is only available in the Results tag.
Mark 24 Jul 2013 11:39
You sir, are a legend. Many thanks for your help today!