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

Support archive

Search for predefined date ranges

Nick 2 Dec 2013 17:07 question, complete

Hi,

How would I create a drop-down that has the following options for Low Search:

Entries created in the last 7 days
Entries created in the last month
etc.

Thanks in advance.

Replies

  1. Low 2 Dec 2013 17:22

    You'd have to use the native start_on/stop_before parameters: http://ellislab.com/expressionengine/...

    LS doesn't provide a way to automate the generation of the drop down, so you'd have to use either a custom query or hard code it. Or use PHP in your template to generate it..

  2. Nick 2 Dec 2013 18:34

    Ok, thanks Low.

  3. Nick 3 Dec 2013 21:11

    Sorry Low, still not quite clear on this.

    I'm using PHP in my template. This works fine, it's the populating of the options that has vexed me. The following shows me the results of the exp:channel:entries pair (last 7 days of entries) instead of allowing me to select that criteria in order to perform a search (which is what I want):

     
    <select name="range:entry_date">
    <option value="">All</option>
    <?php
    $start_time = ee()->localize->format_date('%Y-%m-%d %H:%i', ee()->localize->now - 604800);
    ?>
    <?php echo $start_time; ?>
    {exp:channel:entries channel="mini_360" sort="desc" start_on="<?php echo $start_time; ?>"}
    <option value="{entry_id}"{if entry_id IN ({low_search_range:entry_date})} selected{/if}>
    Last 7 Days
    </option>
    {/exp:channel:entries}

    </select>


    Where have I gone wrong?

  4. Low 4 Dec 2013 08:16

    Couple of things. You're using "range:entry_date", which implies you're targeting the channel field "entry_date" with a range, which should have a start and end date/time. That's not what you're after, I presume.

    Instead, because Low Search can dynamically set all native parameters, including the start_on="" parameter, that is what you need to target, using the value you generate with PHP. That would come down to something like this:

    <?php 
    $week = ee()->localize->format_date('%Y-%m-%d %H:%i', ee()->localize->now - 7 * 86400);
    $month = ee()->localize->format_date('%Y-%m-%d %H:%i', ee()->localize->now - 30 * 86400);
    ?>
    <select name="start_on">
    <option value="">All</option>
    <option value="<?=$week?>"{if low_search_start_on == '<?=$week?>'} selected{/if}>
    Last 7 days
    </option>
    <option value="<?=$month?>"{if low_search_start_on == '<?=$month?>'} selected{/if}>
    Last month
    </option>
    </select>


    Make sense?

  5. Nick 4 Dec 2013 13:05

    Ah, that makes perfect sense! Thank you for your reply.

  6. CNG 6 Apr 2014 13:20

    I don’t suppose there’s an easy way to do this targeting the 'edit_date' instead of 'entry_date' as 'start_on' seems to use?

  7. Low 6 Apr 2014 13:24

    Not at the moment, no. There doesn't appear to be a native parameter that targets the edit_date. I do have an item in my todo list to make native global EE fields like entry_date compatible with the Ranges filter. No ETA on that one, tho.

  8. CNG 6 Apr 2014 13:26

    All right, thanks. I’m trying to flesh out all the possible sorting options I can provide to make a large library more approachable for end users... hence all the questions. :-)

  9. Low 6 Apr 2014 13:27

    Sorting by edit_date shouldn't be a problem. Filtering by that field, however, is currently not possible out of the box.