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

Support archive

Excluding multiple custom field values in a search form

Stephen 4 Jul 2015 01:42 question, complete

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

  1. Low 4 Jul 2015 09:29

    How about, instead of using the hidden input fields, you use this param on the Results tag:

    default:search:cf_schemes_year="not 2015|2016"

    Low 4 Jul 2015 09:31

    Also, because the select-element isn't a multiple one, but a single drop down, you can use this for the name attribute (no square brackets):

    <select name="search:cf_schemes_year">

  2. 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:

     

    {exp:low_search:form result_page="/schemes/search/results" query="{segment_4}"}

    <label>Keywords</label>
    <input type="text" name="keywords" id="keywords" placeholder="Keywords" value="" size="40" />

    <label>Year of Award</label>
    <select name="search:cf_schemes_year">
    <option value="">All</option>
    <option value="2014">2014</option>
    <option value="2013">2013</option>
    <option value="2012">2012</option>
    <option value="2011">2011</option>
    <option value="2010">2010</option>
    </select>

    <input type="submit" value="Search &raquo;" />

    {/exp:low_search:form}



    And here's my results code:

     
    {exp:low_search:results collection="ls_schemes" query="{segment_4}" limit="100" paginate="both" disable="categories|category_fields|member_data" default:search:cf_schemes_year="not 2015|2016"}

    {if count == 1}
    <p>{if low_search_keywords}Searched for <strong>{low_search_keywords}</strong>.{/if} <strong>{absolute_results}</strong> results.</p>

    <table>
    <thead>
    <tr>
    <th>Name</th>
    <th>Region</th>
    <th>Year</th>
    <th>Overall Result</th>
    </tr>
    </thead>
    <tbody>
    {/if}

    <tr>
    <td><a href="/winners/schemes/{url_title}" title="{title}">{title}</a></td>
    <td>{cf_schemes_region}</td>
    <td>{cf_schemes_year}</td>
    <td>{cf_schemes_overall_result}</td>
    </tr>

    {if count == total_results}
    </tbody>
    </table>
    {/if}

    {if switchee_no_results}
    <p>Sorry, your search did not return any results. Please try broadening your search criteria.</p>
    {/if}

    {paginate}
    <p>Page {current_page} of {total_pages} pages {pagination_links}</p>
    {/paginate}

    {/exp:low_search:results}


    Any ideas what I'm doing wrong here at all?

    Thanks,

    Stephen

  3. Low 4 Jul 2015 14:21

    Does using default:search:cf_schemes_year="not 2015&&2016" make a difference?

  4. Stephen 6 Jul 2015 10:21

    Hi Low,

    That fixed it! :-)

    Thanks for your help,

    Stephen