0

I am using Low Search with 2 category select field filters. I'd like to display the selected categories on the page, but when only one category group is used, the results effect the other categories display.

For example:

<p>Industry: {if '{low_search_category}' != ''}{exp:channel:categories show="{low_search_category}" channel="attorneys" category_group="2" style="linear"}{category_name}{/exp:channel:categories}{if:else}All{/if}</p> <p>Practice Area: {if '{low_search_category}' != ''}{exp:channel:categories show="{low_search_category}" channel="attorneys" category_group="3" style="linear"}{category_name}{/exp:channel:categories}{if:else}All{/if}</p>

I have 2 select fields, Industry & Practice Areas. If I select a category from the Industry select field but not from the Practice Area select field, I need the above code to show the correct category for Industry (which it does) but show "All" for Practice Areas since nothing was selected.

With the above code, nothing gets displayed for Practice Areas instead of "All" because {low_search_category} does not distinguish between the 2 different category groups.

Is there any way to achieve this?

1 Answer 1

0

Take a look at the Category Groups option. That might be better for your use case.

Edit: Something along these lines, if you're allowing only one selection per group:

Form

{exp:low_search:form query="{segment_3}"}
    <select name="category:industry">
        <option value="">All industries</option>
        {exp:channel:categories channel="attorneys" category_group="2" style="linear"}
            <option value="{category_id}"{if low_search_category:industry == category_id} selected{/if}>
                {category_name}
            </option>
        {/exp:channel:categories}
    </select>

    <select name="category:area">
        <option value="">All practice areas</option>
        {exp:channel:categories channel="attorneys" category_group="3" style="linear"}
            <option value="{category_id}"{if low_search_category:area == category_id} selected{/if}>
                {category_name}
            </option>
        {/exp:channel:categories}
    </select>

    <button type="submit">Go</button>
{/exp:low_search:form}

Filters

{exp:low_search:filters query="{segment_3}"}
    <p>
        Industry:
        {if low_search_category:industry != ''}
            {exp:channel:categories show="{low_search_category:industry}" channel="attorneys" category_group="2" style="linear"}
                {category_name}
            {/exp:channel:categories}
        {if:else}
            All
        {/if}
    </p>
    <p>
        Practice Area:
        {if low_search_category:area != ''}
            {exp:channel:categories show="{low_search_category:area}" channel="attorneys" category_group="3" style="linear"}
                {category_name}
            {/exp:channel:categories}
        {if:else}
            All
        {/if}
    </p>
{/exp:low_search:filters}

Search results

{exp:low_search:results query="{segment_3}"}
    ...
{/exp:low_search:results}
6
  • Can you give me a little more to go on? I'm not sure I follow.
    – mediapimp
    Sep 23, 2016 at 14:32
  • Edited my answer to include example code.
    – Low
    Sep 23, 2016 at 14:42
  • Thank you so much! Everything works great except for one minor issue I'm having. If I select a category in either or both groups and submit the form, I get the correct results and everything displays as it should. If I then set the select fields back to "All" and submit the form, I get no results. Not sure if this means anything but the last segment in the URL shows e30.
    – mediapimp
    Sep 23, 2016 at 15:05
  • Low, are you able to confirm the issue I'm having?
    – mediapimp
    Sep 28, 2016 at 16:17
  • I just switched the Encode Query to No in the control panel and it now works as it should. Seems the query encoding is what is causing the issue.
    – mediapimp
    Sep 28, 2016 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.