Hide Products from Search Results based on Product Tag

13 0 2

Thank you so much Ninthony! That definitely worked. I also realized that while my code was working for the search page, I kept seeing it in the drop down suggestions of the search bar, but that's in the header.liquid section, not the search.liquid section. So now I know I need to add this functionality somewhere else also to get the drop down from the header search to not return those items as a result, but I can't find where to do that.

My Header section has this:

<div class="search-box elegant-input">
<form class="search-form" action="/search" method="get">
{% include 'svg-search' %}
<label class="search-box-label" for="header-search">{{ 'layout.header.search' | t }}</label>
<input type="text" id="header-search" name="q" autocomplete="off"/>
<button class="button" type="submit"><span class="button__icon">{% include 'svg-chevron-right' %}</span></button>
<input type="hidden" name="type" value="{{ settings.search_type }}" />


My js looks like this:

$(document).on('submit', '.search-form, #search-form, .mobile-search', function(e){
var val = $(this).find('input[name="q"]').val();
if(val.length > 0) {
var term = '*' + val + '*';
var type = $(this).find('input[name="type"]').val() || '';
var linkURL = $(this).attr('action') + '?type=' + type + '&q=' + term;
window.location = linkURL;


Any idea where I need to put this limiter to get the drop down search results from the header bar to display without items tagged with 'nosearch'?


Thank you!