All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Low Search - Predefined Date Range Search by entry_date

Noor Mohammad 18 Nov 2016 00:36 question, complete

Hello Low,

I am trying to use a date range picker which has predefined date ranges and custom date range displayed by JavaScript on the frontend. The HTML code looks like this.

<label>Date Range:</label>
<input type="text" class="sm-form-control daterange1 reportrange pull-left" value="01/01/2016 - 01/31/2016" />


How do I accomplish searching entries by their entry date for such predefined date ranges and also custom date range in one single input field instead of two input fields like in your documentation example.

It must be probably simple, but I hit the brick wall today.

Replies

  1. Low 18 Nov 2016 08:22

    First, try and read the docs on the Ranges filter carefully.

    You can target the entry date, if you need to. But you can also target a custom date field. In any case, the format of the dates that you submit are important. LS uses the php function strtotime to convert the given date to a timestamp. I have found that using the ISO notation (YYYY-MM-DD) is the most non-ambiguous, so I'd recommend using that. But you can try other formats, too.

    As per the docs, you can choose to put a date range in a single field, in which case you need to separate the dates using a pipe |. You can also split the range into two fields, as long as you name the two fields correctly (see docs).

  2. Noor Mohammad 18 Nov 2016 16:21

    Thank you Low for your reply.

    I read the docs again and it was all clear.

  3. Noor Mohammad 19 Nov 2016 04:48

    Hello Low,

    Is it possible to output the range value ({low_search_range:entry_date}) in the results tag, to separate 'from' and 'to' values.

    I wanted to show .. 19 Oct 2016 to 21 Oct 2016,

    However now what I get is .. 2016-11-19|2016-11-21

    Is there anyway to split {low_search_range:entry_date} ?

  4. Low 19 Nov 2016 10:45

    No, sorry. The output of the variable is identical to what was submitted. You'd need to find a way to format that to what you'd want.

    You might be able to do it with a combination of Low List (for looping through the two values) and Low Nice Date (to format each date).

  5. Noor Mohammad 19 Nov 2016 17:15

    Thank you Low. That did the trick, Low List and Low Nice Date worked in harmony.

    I was wondering if we could use category name easily in the front-end output.

    Tried other ways to output, parse-order gets in the way most of the time. It works but has a performance impact.

    If it is supported as a out of the box feature by low search, it would be great!

  6. Low 20 Nov 2016 09:23

    You'd need the channel:categories tag to output the category names, either in a Filters or Form tag, or in a Results tag (within a {if count == 1} conditional).

  7. Noor Mohammad 20 Nov 2016 15:36

    It works well if there are results, and, it doesn't output the category when there are no results, obviously.

    How about outputting the category name (which was searched for) when there are no results?

  8. Low 21 Nov 2016 10:34

    You can either use a Filters tag above the Results tag where you display the search criteria in a readable way, or use the same code in a {if no_results} conditional, which should parse that in the same way.