0

I'm trying to show products that are in X and are also in Y categories. Not all products in X and all products in Y.

Low kindly replied suggesting adding "require_all" to the results tag. This works a charm, but only seems to work a charm when there is more than 1 category in the search query.

Search form:

{exp:low_search:form 
    query="{segment_3}"
    result_page="{prv_template_group}/filter"
    collection="entry_product"
}

    {exp:gwcode_categories 
        channel="{prv_channels}" 
        depth="1" 
        style="linear"
    }

        {if group_start}
            <ul class="list-horizontal list-pill border pad mobile-no-display">
                <li class="title">
                    <h6>{cat_group_name}</h6>
                </li>
        {/if}

            <li>
                <a href="#" class="custom-checkbox{if "{cat_id}" IN ({low_search_category})} active{/if}" data-filter-desktop="filter-{cat_group_id}" data-value="{cat_id}">
                    {cat_name}
                    <input type="checkbox" name="category[]" value="{cat_id}"{if "{cat_id}" IN ({low_search_category})} checked="checked"{/if}>
                </a>

            </li>   

        {if group_end}
            </ul>
        {/if}

    {/exp:gwcode_categories}

    <ul class="list-horizontal list-pill pad">
        <li class="title-offset">
            <input type="submit" class="button large" id="filter-button" value="Update Results">
        </li>
        <li>
            <a href="{site_url}index.php/{prv_template_group}" class="button grey adjust">Clear Filter</a>
        </li>
    </ul>

{/exp:low_search:form}

Filter template:

{exp:low_search:results 
    query="{segment_3}"
    limit="12"
    result_page="{prv_channels}/filter"
    channel="entry_product"
    require_all="category"
}

    {if low_search_no_results}

        {lv_alert_search_null}

    {/if}

    {entry_id}

    {paginate}

        {pagination_links}

            <div class="section pad-b">

                <div class="section-container">

                    <div class="center">

                        {previous_page}
                            <a href="{pagination_url}" class="pagination-arrow prev"></a>
                        {/previous_page}

                        <ul id="pagination-numbers">
                            {page}
                                <li class="{if current_page}active{/if}">
                                    <a href="{pagination_url}">
                                        {pagination_page_number}
                                    </a>
                                </li>
                            {/page}
                        </ul>

                        {next_page}
                            <a href="{pagination_url}" class="pagination-arrow net"></a>
                        {/next_page}

                    </div>

                </div>

            </div>

        {/pagination_links}

    {/paginate}

{/exp:low_search:results}

Any ideas why this is happening?

  • What does Not all products in X and all products in Y mean? Do you have a screenshot of (or link to) the form? – Low Oct 29 '14 at 10:49
  • Also, since you're not using the Keywords filter, you don't need the collection="" parameter (which shouldn't be set on the Form tag in the first place). – Low Oct 29 '14 at 10:50
  • @Low I mean, for example i want it to show all products that belong to BOTH X and Y. I don't want it to show all products that are in X and all products that are in Y. Which is why I used the require all. (X & Y are the categories) I'll drop the collection parameter. – Jason Mayo Oct 29 '14 at 11:13
  • Using require_all will change category="X|Y" to category="X&Y", so showing entries that belong to both X and Y. But I'm guessing (by the template code) you're outputting categories from multiple groups. Are you sure X and Y don't refer to groups? So you're looking for (X1 or X2) and (Y1 or Y2)? – Low Oct 29 '14 at 11:24
  • @Low Yeah thats how I want it, but for example if I only choose X, and update the filter it shows No Results. Even though there is... Thats the problem really. X & Y are the category ID's (In the first block of code at the top) – Jason Mayo Oct 29 '14 at 11:52
1

Took a look and saw you were using the same fields twice: once for mobile, once for desktop. One of those would be hidden based on User Agent, but the checkboxes would be checked anyway, as they were still in the DOM.

That means checking one checkbox would actually check 2, resulting in a parameter like category="1&1", which triggered the No Results.

Removing the hidden fields from the DOM solved the issue.

| 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.