Hide some products from search result

Merim2020
Tourist
7 0 2

Dear All

I am trying to hide wholesale products from the search result. I tagged the product by Wholesale. I have made the following changes in red in the theme search.liquid as recommended in one of the forum posts. But instead of hiding the Wholesale product, the retail product is hidden. Any advice would be highly appreciated.

 

{% for item in search.results %}

{% unless product.tags contains 'Wholesale' %}

{% if item.object_type == 'product' %}
{%- assign product = item -%}
{% include 'product-grid-item' %}
{% else %}
<div class="grid__item grid-search medium-up--one-quarter medium--one-half">
<div class="grid-search__page">
<a href="{{ item.url }}" class="grid-search__page-link">
<span class="grid-search__page-content">
<span class="h4">{{ item.title }}</span>
{% if item.object_type == 'article' and item.image %}
{%- assign img_url = item.image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
<img class="grid-product__image lazyload"
data-src="{{ img_url }}"
data-widths="[180, 360, 540]"
data-aspectratio="{{ item.image.aspect_ratio }}"
data-sizes="auto"
alt="{{ item.title | escape }}">
{% endif %}
{{ item.content | strip_html | truncatewords: 60 }}
</span>
</a>
</div>
</div>
{% endif %}

{% endunless %}

{% endfor %}

Replies 2 (2)
MsMelody
Explorer
46 0 30
Hi @Merim2020 hope this will help, you can try using the  codes below. It worked for me. Thank you! 
 
 
{% for item in search.results %}
 
       
{% unless item.tags contains 'Wholesale' %}
 
      <li class="list-view-item">
        {% if item.object_type == 'product' %}
          {% include 'product-card-list', product: item %}
        {% else %}
          <div class="product-card product-card--list">
            <a href="{{ item.url }}" class="full-width-link">
              <span class="visually-hidden">{{ item.title }}</span>
            </a>
            <div class="list-view-item__link">
              <div class="list-view-item__image-column">
                <div class="list-view-item__image-wrapper product-card__image-wrapper">
                  {% unless item.image == null %}
                    <img class="list-view-item__image" src="{{ item.image.src | img_url: '600x600' }}" alt="{{ item.image.alt | escape }}">
                  {% endunless %}
                </div>
              </div>
 
              <div class="list-view-item__title-column">
                <div class="list-view-item__title" aria-hidden="true">
                  <span class="product-card__title">{{ item.title }}</span>
                </div>
                <div>
                  {% if item.published_at %}{{ item.published_at | date: format: "date" }} &#8212; {% endif %}
                  {{ item.content | strip_html | truncate: 200 }}
                </div>
              </div>
            </div>
          </div>
        {% endif %}
      </li>
    
{% endunless %} 
    
    {% endfor %}
IamMelody
BugShallNotPass
Excursionist
29 1 2

I've developed this app that does the job without modifying your theme code: https://apps.shopify.com/hide-from-search

Xmas Shopify app - beautiful falling snow animation
New Arrivals Shopify app - automatically tag/untag products based on creation/publishing date
Motion - scrolling text announcements
Stash Shopify app - hide products from search results and search engines