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

Support archive

Search by date-range

Dave 28 May 2014 08:20 question, complete

Hi Low,

About a year ago i asked you about filtering by date-range using Low Events and Low Search with help from Low Option. I created a direct link to retrieve posts for a specific date-range by using this line of code:


<a href="{low_search:url low_events:date="now;+7 days"}">This week</a>


I would like to use this same sort of solution in a search from using checkboxes, much like this:

{exp:low_search:form
query="{segment_3}"
result_page="main-templates/zoet-agenda"
form_id="search"
}

<h1>Wanneer</h1>
<input type="checkbox" name="this-week[]" id="this-week" class="css-checkbox" value="">
<label for="this-week" class="css-label"><p>This week</p></label>

<input type="checkbox" name="next-week[]" id="next-week" class="css-checkbox" value="">
<label for="next-week" class="css-label"><p>Next week</p></label>

<button type="submit">Search</button>

{/exp:low_search:form}


Can this be done, and what can i use as a value?
I've put the events in a separate channel and I'm using the collection="events" parameter in my result page tag.

Thanks for your time..

Dave

Replies

  1. Low 28 May 2014 08:37

    Like with all Low Search parameters, the value needed in the input field should be identical to what you'd need hardcoded in the template. In the case of combining Low Search and Low Events, the LE param looks like this:

    {exp:low_events:entries date="now;+7 days"}


    So the input field would be:

    <input name="low_events:date" value="now;+7 days">


    ...as per Low Search's take on parameters (with the addition of the low_events: prefix).

    Now, LE's date parameter doesn't accept multiple ranges. It either accepts a single date, or two (relative) dates, separated by a semi-colon: ;

    This means you cannot use Low Search's way of declaring multiple values. Your checkbox example implies that you want to filter by this week and next week. That's two ranges, and therefore not supported in Low Events.

    Instead, you'd have to use radiobuttons to select a single range. Something like this:

    <label> 
    <input type="radio" name="low_events:date" value="now;+7 days">
    this week
    </label>
    <label>
    <input type="radio" name="low_events:date" value="+7 days;+14 days">
    next week
    </label>


    Make sense?

  2. Dave 28 May 2014 14:48

    Thanks Low that made sense, I used radiobutton for the form and it's works fine now.
    I have another question, could LE and LS also perform a search like above for
    "now" until "the end of the current month".

    Best regards
    Dave

  3. Low 28 May 2014 15:03

    I don't think there's a relative date format for "end of current month". So you'll have to calculate that yourself and use that as the to-date of your custom date range.

  4. Low 28 May 2014 15:06

    Actually, you might try "first day of this month", by the looks of that page I linked above.

  5. Dave 28 May 2014 15:31

    This seems to work.

    <input type="radio" name="low_events:date" id="this-month" class="css-checkbox" value="now;first day of June 2014">
    <label for="this-month" class="css-label"><p>Deze maand</p></label>


    Can LE or even EE generate the 'next month" for: the first day of 'next' month', so i don't have to update the template every month??

  6. Low 28 May 2014 15:45

    LE just has the Archive tag. I don't think EE can do that natively, but there might be an add-on I'm not aware of.

  7. Dave 28 May 2014 15:51

    Sorry, at first sight "first day of this month" didn't work.
    But fortunately it does work...

    So skip my last question!!
    Even this work for events on next month:

    value="first day of next month;last day of next month"

    Thanks