3

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 2

2

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.
6
  • Does this mean I would have to have 2 form fields: orderby and sort? 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'.
    – GDmac
    Jan 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.
    – Low
    Jan 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
1

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"
1
  • 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 the orderby parameter in the opening tag pair. Jan 19, 2013 at 6:56

Your Answer

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

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