Is there a way to sort Low Search results? Say I wanted to sort by {title} in ascending order. Or sort by and {age} field in descending order. Etc.
2 Answers
Anna is right. You can just use the orderby=""
and sort=""
parameters in the Results tag.
To let the end user choose, you can use all {exp:channel:entries}
parameters as input fields in the Form tag, so that includes the orderby
and sort
parameters.
For example:
Sort by <select name="orderby">
<option value="">Relevance</option>
<option value="title">Title</option>
<option value="date">Entry Date</option>
<option value="custom_field">Custom Field</option>
...
</select>
in <select name="sort">
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select> order.
-
Does this mean I would have to have 2 form fields:
orderby
andsort
? I couldn't just have 1 drop down that has the following options for sorting: By Price (ASC), By Price (DESC), etc.? Jan 19, 2013 at 10:34 -
if you don't want visitors to have to select the sort, or you just want predefined settings, then you can use javascript to set a hidden form input field for the sort parameter. Using jQuery or onChange, you can set the hidden 'sort' field to 'asc' or 'desc'.– GDmacJan 19, 2013 at 11:47
-
I was hoping for a non-JS solution. The JS solution is probably more user friendly than having 2 fields, though. Jan 19, 2013 at 11:54
-
It isn't possible to combine the two parameters into one at the moment, but I can see how that would be a nice feature request.– LowJan 19, 2013 at 16:19
-
<option value="price:asc">Price - Lowest to Highest</option>
- something like that? Feature requested! Jan 24, 2013 at 5:53
With Low Search you can sort by relevance which is the default setting or you can sort by using any parameter the native channel:entries tag can use.
You'll probably want to use the orderby="" parameter:
orderby="title"
orderby="name_of_field"
-
What if I wanted the users to choose the
orderby
? Can I provide it as a<select>
in Low Search form? That way Low Search results will just take it as part of its parameters? I don't want to hard code theorderby
parameter in the opening tag pair. Jan 19, 2013 at 6:56