1

I have a checkbox to filter which categories that the simple search form is actually searching in. Is there a way to do this properly within EE? Here is the code below.

{exp:search:simple_form 
    channel="promo_video" 
    search_in="entries" 
    no_result_page="" 
    result_page=""}
    <input type="text" name="keywords" id="keywords" placeholder="Search here" />
    <input type="submit" id="submit-button" class="submit-search" value="Submit"/>
    <div class="search-group-title">Filter:</div> 
    <ul class="search-group">
        <li><input type="checkbox" name="filters" id="{promo_description}" value="152"/>Sermon Description</li>
        <li><input type="checkbox" name="filters" id="{promo_video_title}" value="42"/>Series Title</li>
        <li><input type="checkbox" name="filters" id="{sermon_notes_txt)" value="241"/>Sermon Notes</li>
        <li><input type="checkbox" name="filters" id="{youtube_transcript}" value="239"/>Youtube Transcript</li>
        <li><input type="checkbox" name="filters" id="{meta_tags}" value="240"/>Tags</li>   
    </ul>
{/exp:search:simple_form}

{exp:channel:entries channel="promo_video" orderby="date"}
    <div class="tile">
        <div class="video-title" style="font-weight: bold;">{promo_video_title}</div>
        <div class="promo-description">{promo_description}</div>
        <div class="meta-tags">{meta_tags}</div>
    </div>
{/exp:channel:entries}

Essentially, if the series title is selected, then the search would only take place within the {promo_video_title} field group. Also, if there are multiple boxes checked, for example, Sermon notes and Series title, only the {promo_video_title} and the {sermon_notes_txt} field groups would be searched. Right now it currently displays all of the entries from the promo_video channel, but I was wondering if the results were able to be filtered.

1
  • I understand that querying the search results is not provided within the code. I was just wondering if it was possible to filter searches based on specific field groups.
    – Ovii
    Commented Jun 16, 2021 at 16:31

2 Answers 2

1

Simple search does not allow you to constrain a search within categories. To do what you describe you have (at least) two options:

  1. Use simple search as now and then dump the unfiltered output from any search into a set of layout variable arrays, in which you capture (along with the search content / results to be displayed) the category(ies) assigned to each search result; with that you can then use conditional elements in your template to control which categories get displayed on the page in response to the checkboxes chosen. It is not super efficient if you are likely to be generating huge numbers of search results each time, but provided the numbers involved are small it should work fairly well: for this to work though you'll need to split your search-results template processing across two templates (so that you can use the layout variable arrays you defined in the template output).
  2. Use a more sophisticated search function that allows you to limit responses by category such as Low Search - there may be other add-ons that do this too, but for many Low Search remains the go-to for sophisticated search.

HTH

2
  • Is there any documentation on low search? I was looking onto their website and the page says that it will be added soon
    – Ovii
    Commented Jun 16, 2021 at 18:46
  • The documentation for Low Search is here - gotolow.com/addons/low-search/docs Commented Jun 16, 2021 at 20:42
2

EE has an "advanced" search feature as well which allows category filtering - see https://docs.expressionengine.com/latest/add-ons/search/advanced.html for example code.

Your Answer

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

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