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

Support archive

Filtering a multi-category search with a specific category?

Doug Biggerstaff 17 Mar 2020 19:34 question, complete

Hello, is it possible to execute a search between two categories where one is a filter of the other?

For example:

category.type
-------------------
report
webinar
article

category.sector
---------------------
nonprofit
commercial
government

Can I use category.sector as a filter on the category search so that only 'reports' or 'webinars' in the 'commercial' sector return?

Such as...

{exp:low_search:form
query="{segment_3}"
collection="items"
channel="items"
require_all="category"
filter="category.sector"
limit="1000"
}


Thanks very much,
Doug

Replies

  1. Low 18 Mar 2020 08:24

    If you want to filter by two separate category groups (combining AND and OR filtering), then look at the Categories filter: https://gotolow.com/addons/low-search...

    If you want one list of categories to be dependent on what you select in another, then that's just how you set up your form. See this blog post on how to do so with JavaScript and a nested category structure: https://gotolow.com/blog/dynamic-drop...

  2. Doug Biggerstaff 18 Mar 2020 16:59

    Thanks very much Low,

    I have played with 'filter="category:1"' in the tags, but it's not responding as I expect. I'm seeing what appears to be OR across both categories which is adding undesired items in the result.

    I've tried category:group_id, category:group_url_title and category:group_name with no apparent impact.

    For clarity, an example of what I'm looking for, from the listing in my OP, is...

    Report OR Webinar AND NonProfit.

    So it can be any selected type, but has to be the selected sector.

    I should add that entries have only 1 type, and 1 sector.

    Thanks again,
    Doug

  3. Low 19 Mar 2020 07:52

    I don't know where you're getting the filter="category:1" syntax from, but that's not correct.

    You should be using something like category:type="1|2" category:sector="3|4" which translates to category ID (1 OR 2) AND (3 OR 4).

    To achieve this in your form, use name="category:type[]" and name="category:sector[]" in your multiple-select elements or checkboxes.

    The collection=, channel=, require_all= and limit= parameters are not valid on the Form tag. filter= is a non-existent parameter in Low Search.

  4. Doug Biggerstaff 19 Mar 2020 13:03

    Thanks very much Low,

    name="category:type[]" has had the biggest impact.

    However, now that they're included, the selected values don't persist on the results page and are not identified in the 'Sorry, no results for:..." string.

    As per your suggestion, I'm using the following form input...


    <input id="{category_url_title}" type="checkbox" name="category.type[]" value="{category_id}"{if low_search_category ~ '/\b'.category_id.'\b/'} checked{/if}>


    How is {low_search_category} modified to accept the category name (type)?

    I have reviewed the Parameters docs but the syntax is not clear.

    Thanks again,
    Doug

  5. Low 19 Mar 2020 19:59

    Use this instead:

    {if low_search_category:type ~ '/\b'.category_id.'\b/'}


    ...and make sure you use a colon :, not a period in the parameter name.

    The rule is, if the parameter name is "foo" and the value is "bar", then use

    - foo="bar" : in the Results tag
    - <input name="foo" value="bar"> : inside the Form
    - {low_search_foo} : to output "bar" inside the Form or Results tags (ignore any square brackets here)

    Make sense?

  6. Doug Biggerstaff 19 Mar 2020 21:25

    Thanks very much Low,

    It does - I'm good to go now.

    Appreciate it,
    Doug