How to hide certain pages from storefront search - Studio 11.0.0

abippn
Visitor
3 0 0

I previously used this post to hide certain pages from storefront search and it worked. But when I updated my Studio theme to version 11.0.0 from 10.0.0, it stopped working and these pages are now showing on my storefront search again. This is how my code looks currently. Can anyone help with this?

 

 

 

                {%- for item in search.results -%}
                  {% assign lazy_load = false %}
                  {%- if forloop.index > 2 -%}
                    {%- assign lazy_load = true -%}
                  {%- endif -%}
                  {% unless item.metafields.custom.hide_from_storefront_search == 1 %}
                  <li class="grid__item{% if settings.animations_reveal_on_scroll %} scroll-trigger animate--slide-in{% endif %}"
                    {% if settings.animations_reveal_on_scroll %}
                      data-cascade
                    {% endif %}>
                    {%- case item.object_type -%}
                      {%- when 'product' -%}
                        {%- capture product_settings -%}{%- if section.settings.product_show_vendor -%}vendor,{%- endif -%}title,price{%- endcapture -%}
                        {% render 'card-product',
                          card_product: item,
                          media_aspect_ratio: section.settings.image_ratio,
                          image_shape: section.settings.image_shape,
                          show_secondary_image: section.settings.show_secondary_image,
                          show_vendor: section.settings.show_vendor,
                          show_rating: section.settings.show_rating,
                          lazy_load: lazy_load
                        %}
                      {%- when 'article' -%}
                        {% render 'article-card',
                          article: item,
                          show_image: true,
                          show_date: section.settings.article_show_date,
                          show_author: section.settings.article_show_author,
                          show_badge: true,
                          media_aspect_ratio: 1,
                          lazy_load: lazy_load
                        %}
                      {%- when 'page' -%}
                        <div class="article-card-wrapper card-wrapper underline-links-hover">
                          <div class="card card--card card--text ratio color-{{ settings.blog_card_color_scheme }}" style="--ratio-percent: 100%;">
                            <div class="card__content">
                              <div class="card__information">
                                <h3 class="card__heading">
                                  <a href="{{ item.url }}" class="full-unstyled-link">
                                    {{ item.title | truncate: 50 | escape }}
                                  </a>
                                </h3>
                              </div>
                              <div class="card__badge {{ settings.badge_position }}">
                                <span class="badge color-{{ settings.color_schemes | first }}">{{ 'templates.search.page' | t }}</span>
                              </div>
                            </div>
                          </div>
                        </div>
                    {%- endcase -%}
                  </li>
                  {% endunless -%}
                {%- endfor -%}

 

 

Replies 3 (3)

PaulNewton
Shopify Partner
6339 579 1350

You can get rid of the {% unless %} wrapper.

Immediately after the {% for.. %} tag use the following :

 

{% if item.metafields.seo.hidden == 1 %}{% continue %}{% endif -%}

 

 

If you need this customization setup for then contact me by mail for services.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail.
Contact info in signature.

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


abippn
Visitor
3 0 0

Hi @PaulNewton, thank you for writing back! Unfortunately, this didn't work for me. I tried replacing 'item.metafields.seo.hidden' in your code to  'item.metafields.custom.hide_from_storefront_search' as well but that didn't work either.

For further context, I have a page metafield set up (Namespace and key: custom.hide_from_storefront_search) and for the pages that I don't want to show up on storefront search, I input the integer value of 1 in this metafield. Using the solution I linked in the original post above with version 10.0.0, it used to work but now it doesn't on version 11.0.0.

 

This is how my code looked after trying out your solution, did I do it correctly?

 

                {%- for item in search.results -%}
                  {% if item.metafields.custom.hide_from_storefront_search == 1 %}{% continue %}{% endif -%}
                  {% assign lazy_load = false %}
                  {%- if forloop.index > 2 -%}
                    {%- assign lazy_load = true -%}
                  {%- endif -%}
                  <li class="grid__item{% if settings.animations_reveal_on_scroll %} scroll-trigger animate--slide-in{% endif %}"
                    {% if settings.animations_reveal_on_scroll %}
                      data-cascade
                    {% endif %}>
                    {%- case item.object_type -%}
                      {%- when 'product' -%}
                        {%- capture product_settings -%}{%- if section.settings.product_show_vendor -%}vendor,{%- endif -%}title,price{%- endcapture -%}
                        {% render 'card-product',
                          card_product: item,
                          media_aspect_ratio: section.settings.image_ratio,
                          image_shape: section.settings.image_shape,
                          show_secondary_image: section.settings.show_secondary_image,
                          show_vendor: section.settings.show_vendor,
                          show_rating: section.settings.show_rating,
                          lazy_load: lazy_load
                        %}
                      {%- when 'article' -%}
                        {% render 'article-card',
                          article: item,
                          show_image: true,
                          show_date: section.settings.article_show_date,
                          show_author: section.settings.article_show_author,
                          show_badge: true,
                          media_aspect_ratio: 1,
                          lazy_load: lazy_load
                        %}
                      {%- when 'page' -%}
                        <div class="article-card-wrapper card-wrapper underline-links-hover">
                          <div class="card card--card card--text ratio color-{{ settings.blog_card_color_scheme }}" style="--ratio-percent: 100%;">
                            <div class="card__content">
                              <div class="card__information">
                                <h3 class="card__heading">
                                  <a href="{{ item.url }}" class="full-unstyled-link">
                                    {{ item.title | truncate: 50 | escape }}
                                  </a>
                                </h3>
                              </div>
                              <div class="card__badge {{ settings.badge_position }}">
                                <span class="badge color-{{ settings.color_schemes | first }}">{{ 'templates.search.page' | t }}</span>
                              </div>
                            </div>
                          </div>
                        </div>
                    {%- endcase -%}
                  </li>
                {%- endfor -%}

 

PaulNewton
Shopify Partner
6339 579 1350

It looks correct but I have no idea as to the validity of what values you have in what products metafields or the search terms your using ,etc etc.

Double check that is not the only relevant area of code that goes over search results.

 

Try disabling javascript in your browser for that site and testing it.

If it works with javascript disabled then theres some javascript that runs, that ignores the underlying liquid code,  which would have to be adjusted.

 

 

Good Luck.

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org