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

Support archive

Search: Category 1, 2, 1 and 2

Franz 16 Feb 2014 21:28 question, complete

Hi Low,

I have another question. I can't quite figure out how to give the 3 mentioned options. Right now it shows only Category 1 and 2 but I'm unable to have it list all entries Category 1 and 2.


<div class="form-group">
<label for="exampleInputPassword1">Kaufen oder Mieten?</label>
<select name="category[]" id="variant" class="form-control">
{exp:channel:categories category_group="1" style="linear"}
<option value="{category_id}"{if category_id IN ({low_search_category})} selected{/if}>
{category_name}
</option>
{/exp:channel:categories}
</select>
</div>

Replies

  1. Low 16 Feb 2014 22:28

    it shows only Category 1 and 2 but I'm unable to have it list all entries Category 1 and 2


    Am I right in reading the same thing twice, here? "Category 1 and 2" in both cases?

    I'm assuming you mean "1 OR 2" (or both) and "1 AND 2" (must be both). If that's the case, look at the require_all="" parameter -- try adding require_all="category" to your Results tag.

  2. Franz 16 Feb 2014 22:41

    Hi Low,

    Thanks for your quick response.
    - The code I show outputs a drop down. I would like it to have the following options:

    1. Category 1
    2. Category 2
    3. Category 1 and 2 (Show all entries)

    So if they want to see all entries rather then a specific one, they will be able to select option 3. Sorry If I'm overseeing something.

  3. Low 17 Feb 2014 07:23

    If you're generating the options using the channel:categories tag, you cannot get that last option -- you'd have to hard-code it.

    Make sure require_all="category" is indeed in your Results tag, and add this to your select-element:

    <option value="1|2">Category 1 and 2</option>


    Then, instead of using the IN conditional, use the standard {if category_id == low_search_category} ... {/if} and for the last option, use {if low_search_category == '1|2'}.

  4. Franz 17 Feb 2014 09:02

    Hi Low,

    Thanks for getting me on the right path. I was looking to show all entries, no matter which category they are assigned to. Now I'm submitting and empty value and this seems to work.

    Is this the proper way of doing so?

    Thanks for your patience!

    <fieldset>

    <div class="form-group">
    <label for="exampleInputPassword1">Immobilientyp</label>

    <select name="category[]" id="type" class="form-control">
    {exp:channel:categories category_group="2" style="linear"}
    <option value="{category_id}"{if category_id IN ({low_search_category})} selected{/if}>
    {category_name}
    </option>
    {/exp:channel:categories}
    </select>
    </div>

    <div class="form-group">
    <label for="exampleInputPassword1">Kaufen oder Mieten?</label>
    <select name="category[]" id="variant" class="form-control">
    {exp:channel:categories category_group="1" style="linear"}
    <option value="{category_id}"{if category_id == low_search_category}{/if}>{category_name}</option>
    {/exp:channel:categories}
    <option value=""{if low_search_category == ''}{/if}>Category 1 or 2</option>
    </select>
    </div>

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

    </fieldset>

  5. Low 17 Feb 2014 09:14

    Ah, you have 2 select elements, each representing a category group. Then take a look at this code: http://pastie.org/private/fzsjkck03zg...

    Each drop-down has an empty value, ignoring that group. Is that what you're after?