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

Support archive

Having problems with ANY and AND searching categories using low search and checkboxes

ZenBug 29 Nov 2013 21:42 question, complete

I have several entries, each of which can have any number of categories assigned.

I want to build a search form using Low Search that lets the user select some categories, and also select "Show me entries with ANY of my selections" or "Show me entries with ALL of my selections".

There's an example very similar to this in the docs, but I can't seem to get mine to work. I do get the correct results when I select ANY, but for ALL, I get no results.

Here's my code:

 
{exp:low_search:form
query="{segment_2}" {!-- Don’t forget this! --}
result_page="signs-and-symptoms" {!-- Can also be defined in the Settings. --}
form_id="search"
}
<fieldset>

<input type="hidden" name="require_all[]" value="category">{!-- Do I need this field in my case?? --}

<div>
<div class="group">
{exp:channel:categories
channel="{pr-channel}"
category_group="29"
style="linear"
}
<label>
<input type="checkbox" name="category:symptom[]" value="{category_id}"{if category_id IN ({low_search_category:symptom})} checked{/if}>
{category_name}
</label>
{/exp:channel:categories}

<select name="require_all[]">
<option value=""{if 'category:symptom' NOT IN ({low_search_require_all})} selected{/if}>Any</option>
<option value="category:symptom"{if 'category:symptom' IN ({low_search_require_all})} selected{/if}>All</option>
</select>

</div>
</div>

</fieldset>

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

{/exp:low_search:form}


Any help is appreciated.

Replies

  1. Low 29 Nov 2013 21:59

    Remove this:

    <input type="hidden" name="require_all[]" value="category">


    Then change name="category:symptom[]" to name="category[]".

    Then use this conditional to check the checkboxes:

    {if category_id IN ({low_search_category})} checked{/if}


    And instead of a select dropdown to choose between any/all selected categories, use a checkbox, something like this:

    <input type="checkbox" name="require_all" value="category" 
    {if low_search_require_all == 'category'} checked{/if}> Require all


    When checked, it should return entries that have all selected categories assigned to it.

  2. ZenBug 2 Dec 2013 21:20

    Excellent. Thanks Low!