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

Support archive

Low Search - Date Range Problems

arvinsim 24 Jul 2013 09:09 question, complete

I have this markup in my low search form


<select id="range_to_birthdate" name="range-to:birthdate">
<option value="1995-07-23">18</option>
<option value="1994-07-23">19</option>
<option value="1993-07-23">20</option>
<option value="1992-07-23">21</option>
<option value="1991-07-23">22</option>
......
</select>

<select id="range_from_birthdate" name="range-from:birthdate">
<option value="1995-07-23">18</option>
<option value="1994-07-23">19</option>
<option value="1993-07-23">20</option>
<option value="1992-07-23">21</option>
<option value="1991-07-23">22</option>
......
</select>


I have 2 problems

It doesn't seem to do inclusive search. When I try to search for age 25 to 26 for example, I get only those age 25. I wanted to return both 25 and 26 profiles

I have a hook(low_search_pre_search) that swaps the values of the ranges in case someone puts the input in the wrong order. However, even if I do, I still get the same values as when i submitted them

Here is my code for swapping


if (isset($data['range-from:birthdate']) === TRUE && isset($data['range-to:birthdate']) === TRUE)
{
// Make sure that the range from is greater than range to. Swap if necessary
$range_from_timestamp = strtotime($data['range-from:birthdate']);
$range_to_timestamp = strtotime($data['range-to:birthdate']);

if ($range_from_timestamp > $range_to_timestamp)
{
$temp1 = $data['range-from:birthdate'];
$temp2 = $data['range-to:birthdate'];

// Swap
$data['range-from:birthdate'] = $temp2;
$data['range-to:birthdate'] = $temp1;
}
}

return $data;


Any kind of help is appreciated.

Replies

  1. Low 24 Jul 2013 10:31

    For your first issue; it works as designed. Look at the dates. Setting the From and To dates to 1994-07-23 and 1995-07-23 (which would be ages 18 to 19 in your case) spans a single year. Ages are different from dates. If you'd want all 18 and 19 year olds, you'd have to use 1994-07-23 to 1996-07-22.

    Makes even more sense if you're looking for a single age, for example all 20 year olds. Then, with your example, you'd have to choose 20 in both drop downs. Which gives you from 1993-07-23 to 1993-07-23, which will probably give you 0 results, unless the 23rd is someone's birthday. Instead, you'd want 1993-07-23 to 1994-07-22, which spans a single year and should give you all 20-year olds.

    As for your extension issue... Are you sure the extension is fired at all? What about template debugging data and output profiler data? Can you see the query generated?

  2. arvinsim 25 Jul 2013 02:32

    I guess you are correct. In the all 20 years old problem I could do

    1993-07-23 - 1994-07-23

    or

    1993-07-23 12:00 AM - 1993-07-23 11:59 PM


    As for your extension issue... Are you sure the extension is fired at all? What about template debugging data and output profiler data? Can you see the query generated?


    Yup. I tried both low_search_pre_search and low_search_post_search. The values submitted to Low search is swapped because I get correct results. It is the values in exp:low_search:form that is the problem. I still get the originals

  3. Low 25 Jul 2013 12:15

    . It is the values in exp:low_search:form that is the problem. I still get the originals


    Correct, Low Search will always display the actual posted values in the Form or Filters tags. You could use JavaScript to alter values on the front-end.