2

just looking for a bit of help in expanding my sites search capabilities.

I have a very basic search box at the moment, handled by Low Search.

It searches one channel (a single collection) and returns results fine.

What I would like is to be able to filter these results based in custom field data within the entries.

For example, I have a checkbox field that lists several "features" for that entry.

I would like the user to be able to select one (or more) of these features and then update the search results with the entries that have these features with the custom field.

I'm thinking something along the lines of the filter section of Devotee.

The Low Search docs have info on creating a more complex search form with more options, but I cannot seem to see anything about "filtering" results.

Just not sure how to implement it, so any pointers would be good!

UPDATE

Right, I've had a go at trying this out, but cannot get it to work properly.

Maybe its the way I'm set up.

I have a main listing template, that is changed via Switchee, with one of the variables being my search results template, however my actual search form is contained within a sidebar that is within a Low Variable :)

This is my search form code:

{exp:low_search:form query="{segment_3}" result_page="walks/results"}

            <label>Search for a walk:</label>
            <input type="text" name="keywords" id="keywords" class="span5" />


            {exp:low_options:walk_features_new}
                {options}
                    <label>
                        <input type="checkbox" name="walk_features_new[]" value="{option:value}"
                        {if "{option:value}" IN ({low_search_search:walk_features_new})} checked="checked"{/if} />
                        {option:label}
                    </label>
                {/options}
            {/exp:low_options:walk_features_new}

            <button class="btn btn-block btn-blue" type="submit">Search</button>

        {/exp:low_search:form}

Note: the IN-conditional works in EE 2.8.1 or below. If you're using EE 2.9 or up, use a different syntax.

And my results page has the following within the switchee case:

{exp:low_search:results query="{segment_3}" collection="walks" search_mode="all"  status="open|new" show_expired="yes" dynamic="off" limit="10" paginate="bottom"}

                {lv_walkdetails_main}

                {lv_pagination}

                {if switchee_no_results}

                    <p>Sorry, no results!</p>

                {/if}

            {/exp:low_search:results}

When i run a search via the search box (keywords) it works fine, but when I select one of the options, it does provide correct results, or remember what was selected.

Anything obvious wrong?

(not sure if it helps, or makes a difference but it's a P&T checkbox field.)

1 Answer 1

7

For the record, I know devot-ee uses Low Search for searching only. The filtering you mention is done by a custom add-on they have developed internally. But that doesn't mean you can't achieve something similar with Low Search; you just have to approach things a bit differently.

First, you need to create a Low Search form on the results page. You then add the query parameter to it, just like the Results tag. This will make the Form tag 'remember' the posted query.

You then need to add the checkbox list to the form tag. If you're not going to hard-code it in your template, you could use Low Options (free) to generate it. For example, say your checkbox field is called features, then use this code inside your Form tag:

{exp:low_options:features}
    {options}
        <label>
            <input type="checkbox" name="search:features[]" value="{option:value}"
            {if "{option:value}" IN ({low_search_search:features})} checked="checked"{/if} />
            {option:label}
        </label>
    {/options}
{/exp:low_options:features}

...which will generate a list of checkboxes, remembering which was checked when the form was submitted again.

Note that this will give you results for any of the checked values, not all. If you only want entries that have all the features checked, make sure you add that to the require_all parameter of the Form tag: require_all="search:features".

Also note: the IN-conditional works in EE 2.8.1 or below. If you're using EE 2.9 or up, use a different syntax.

9
  • That's brilliant, thanks for the response. I shall have a look at trying it out very soon, and will report back. I think I understand it!
    – shorn
    Jan 21, 2013 at 10:15
  • Sorry for the delay, my internet has been down, and haven't been able to try this out. Will update soon!
    – shorn
    Jan 23, 2013 at 15:24
  • Updated my question as have now had a chance to try it out.
    – shorn
    Feb 4, 2013 at 1:05
  • Sorry, had a slight error in my example code. The input name should be search:features[], just like you would use it in the channel:entries tag: search:features="foo|bar". Updated my answer to reflect this.
    – Low
    Feb 4, 2013 at 9:22
  • Thanks Low, just tried it out and.... still not working! The results page loads, but the options selected have no bearing in the results, nor does it remember any of the selections?
    – shorn
    Feb 4, 2013 at 14:43

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.