0

I am creating a website for an apartment complex where the user can find apartments based on a floorplan. I have Low Search installed and am attempting to create a filtered search form using categories assigned to each apartment.

Question: is there a way to combine multiple categories into one option in a select dropdown? For example, I have six categories (floor 1, floor 2, floor 3, floor 4, floor 5, floor 6).

I want two select options where each option returns results for three of the six categories. If you choose the first option, it will return results for entries categorized with floor 1, floor 2 or floor 3. If you choose the second option you get entries categorized with floor 4, floor 5 or floor 6.

I've tried the following, within a Low Search form tag:

<label>What floor do you like?</label>

<select name="category[]">
  <option value="">--</option>
    {exp:channel:categories
      category_group="1"
      show="1|2|3"
      style="linear"
    }
      <option value="{category_id}"{if low_search_category ~ '/\b'.category_id.'\b/'} selected{/if}>
          I'm afraid of heights, lower floors are preferred
      </option>
    {/exp:channel:categories}
    {exp:channel:categories
      category_group="1"
      show="4|5|6"
      style="linear"
    }
      <option value="{category_id}"{if low_search_category ~ '/\b'.category_id.'\b/'} selected{/if}>
          The higher the better!
      </option>
    {/exp:channel:categories}
</select>

But what displays in the select dropdown is:

--
I'm afraid of heights, lower floors are preferred
I'm afraid of heights, lower floors are preferred
I'm afraid of heights, lower floors are preferred
The higher the better!
The higher the better!
The higher the better!

I am on EE 2.8.1 with Low Search 3.5.2. Any insight provided would be most appreciated!

0

The channel:categories tag will loop through the categories given, hence the 3 rows per tag. If you only need 2 <option>s, but they need to target 3 categories each, then hard-coding the category IDs would be the way to go. Also, since you're allowing the user to select one option (rather than multiple), you don't need the square brackets in the name attribute.

For your copy/paste convenience:

<select name="category">
    <option value="">--</option>
    <option value="1|2|3"{if low_search_category == '1|2|3'} selected{/if}>
        I'm afraid of heights, lower floors are preferred
    </option>
    <option value="4|5|6"{if low_search_category == '4|5|6'} selected{/if}>
        The higher the better!
    </option>
</select>
  • Thanks Low! As always, prompt responses and great support. – Eric Feb 22 '15 at 17:32
  • Follow up question on this Low. I have multiple selects in the search form, each representing a single choice from a category group. I can remove the square brackets from all of them? – Eric Feb 23 '15 at 16:45
  • Make it a new question with example code, so I'm sure I understand you correctly. – Low Feb 23 '15 at 16:54
  • I figured out my issue, apologies for the vague question. I appreciate your quick response. – Eric Feb 23 '15 at 18:30

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.