1

I have a low search filter set up which works great however the client now wants to separate the results by country of origin. This should be possible as the country is set by another custom field.

I see this working with Stash, but cannot seem to wrap my head around how to do it.

Working code with all results sorted by title:

{exp:low_search:form query="{segment_3}" result_page="{transcribe:language_abbreviation}/branch-locator/filter" form_id="region-filter" form_onchange='submit()'}
  <div class="form-group">
    <select class="form-control" name="child:pl_branch_region">
      {exp:channel:entries
        channel="regions"
        dynamic="no"
        orderby="title"
        sort="asc"
        disable="categories|member_data|pagination|custom_fields"
      }
      {if count=="1"}<option value="">All ({total_results})</option>{/if}
  <option value="{entry_id}"{if low_search_child:pl_branch_region == entry_id} selected{/if}>
        {title}
    </option>
      {/exp:channel:entries}
    </select>
  </div>
{/exp:low_search:form} 

What I need to do is separate the results into country which is another field {reg_country} with value of either "can" or "usa"

Ideally the option list would be output like this:

Canada Alberta British Columbia Manitoba etc.... USA Conneticut Maine et..

currently all results are listed alphabetically but not sorted by country.

2

You can do this with a Stash list nested inside itself, like so:

{exp:stash:set_list name="regions" parse="yes"}
    {exp:channel:entries
        channel="regions"
        dynamic="no"
        orderby="title"
        sort="asc"
        disable="categories|member_data|pagination"
    }
        {stash:entry_id}{entry_id}{/stash:entry_id}
        {stash:title}{title}{/stash:title}
        {stash:reg_country}{reg_country}{/stash:reg_country}
    {/exp:channel:entries}
{/exp:stash:set_list}

{exp:stash:get_list name="regions" unique="reg_country"}
    <optgroup label="{reg_country}">    
        {exp:stash:get_list:nested name="regions" prefix="nested" match="#^{reg_country}$#" against="reg_country"}
            <option value="{nested:entry_id}"{if low_search_child:pl_branch_region == nested:entry_id} selected{/if}>
                {nested:title}
            </option>
        {/exp:stash:get_list:nested}
    </optgroup>
{/exp:stash:get_list}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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