Excluding multiple custom field values in a search form
Hi Low,
I've got a channel named 'schemes' and it's got over 5,000 entries in it. I have a custom field named cf_schemes_year in this channel, and it contains the year the entry won an award, going from 1959 to 2016.
I'm trying to exclude entries that have a value in this custom field of 2015 or 2016 (as I can't show the last 2 year's worth of entries), but also allow the user to manually select a year from the Year of Award dropdown in the search form.
With the code below, the Year of Award dropdown works finen if the user manually selects a year, but when the user leaves this as 'any', the hidden fields I have in place to exclude entries with a year of 2015 or 2016 aren't working, so the results show entries for all years, including those from 2015 and 2016 that I'm trying to hide.
Can you see what I'm doing wrong here at all?
{exp:low_search:form result_page="/schemes/search/results" query="{segment_4}"}
<p><label>Keywords</label></p>
<p><input type="text" name="keywords" id="keywords" placeholder="Keywords" value="" size="40" /></p>
<p><label>Year of Award</label></p>
<p><select name="search:cf_schemes_year[]">
<option value="">All</option>
<option value="2014">All</option>
<option value="2013">All</option>
<option value="2012">All</option>
</select></p>
<input type="hidden" name="search:cf_schemes_year[]" value="not 2015" />
<input type="hidden" name="search:cf_schemes_year[]" value="not 2016" />
{/exp:low_search:form}
Thanks for any help,
Stephen
Replies
Low 4 Jul 2015 09:29
How about, instead of using the hidden input fields, you use this param on the Results tag:
Stephen 4 Jul 2015 12:54
Hi Low,
Thanks for the responses. Those two tweaks didn't work though, I'm afraid.
When I run a search and the 'Year of Award' dropdown is left as 'Any', I'm getting all entries in the results (including those for 2015 and 2016). When I change this dropdown to a certain year, then it's showing just results for that year as expected.
I'm using EE 2.7.3 and Low Search 4.1.1.
Here's my search form code:
And here's my results code:
Any ideas what I'm doing wrong here at all?
Thanks,
Stephen
Low 4 Jul 2015 14:21
Does using default:search:cf_schemes_year="not 2015&&2016" make a difference?
Stephen 6 Jul 2015 10:21
Hi Low,
That fixed it! :-)
Thanks for your help,
Stephen