How to remove blog posts and pages from search results

Solved

How to remove blog posts and pages from search results

TatiGGG
Visitor
3 0 0

Hi, I've been trying to find a way to remove the blog posts and pages from showing up in the internal search results on our website. I found similar questions posed on Community but they're for different theme. 

 

The solution suggested was to add this  <input type="hidden" name="type" value="product'>  below {{ routes.search_url }} in the main-search.liquid file

 

Our theme is Xtra and so far this is the code that I'm looking at under that main-search.liquid file:

 

 </header>
          <form action="{{ routes.search_url }}" method="get" class="f8se no-js">
    				<p class="m10">{{ 'search.amount_of_results' | t: count: search.results_count, amount: search.results_count }}</p>
    				<p>
    					<label for="fea" class="hidden">{{ 'search.title' | t }}</label>
    					<input type="search" id="fea" name="q" placeholder="{{ 'search.search_form.placeholder' | t }}" autocomplete="off" required {% if search.performed %}value="{{ search.terms }}"{% endif %}>
    					<button type="submit">{{ 'search.search_form.submit' | t }}</button>
    				</p>
    			</form>
          {%- liquid
            if sorting_block == nil and show_filters_and_menu
              render 'filters-sorting', display: 'mobile-filter-button', sticky: section.settings.filter_mobile_sticky, show_filters: show_filters
            endif
          -%}
        {%- when 'sorting' -%}
          {%- render 'filters-sorting',
            display: 'sorting',
            sticky: section.settings.filter_mobile_sticky,
            show_filters: show_filters,
            origin: "search",
            object: search,
            show_amount_of_products: section.settings.show_amount_of_search_results,
            collection_view: collection_view
          -%}
        {%- when 'results' -%}
            {% paginate search.results by section.settings.pagination_qty %}
              {%- liquid
                assign products = search.results | where: 'object_type', 'product'
                assign articles = search.results | where: 'object_type', 'article'
                assign pages = search.results | where: 'object_type', 'page'
              -%}
              {%- if section.settings.pagination_type == 'button' and paginate.previous %}
                {% render 'pagination',
                        paginate: paginate,
                        pagination_type: section.settings.pagination_type,
                        prev_button: true
                %}
              {%- endif -%}
              <div class="results">
                {%- if products.size > 0 -%}
                  <ul id="collection" class="l4cl {% if settings.enable_quick_buy %}with-quick-buy{% endif %}{% if collection_view == 'list' %} list{% endif %}{% unless show_filters_and_menu %} mobile-wide{% endunless %}{% if section.settings.products_per_row_mobile == '1' %} w100-mobile{% endif %}" {{ block.shopify_attributes }}>
                    {%- for product in products -%}
                      {%- liquid
                        capture placeholder_int
                          cycle 1, 2, 3, 4, 5, 6
                        endcapture
                      -%}
                      {%- render 'product-item',
                        product: product,
                        placeholder_int: placeholder_int,
                        width_class: width_class,
                        type: 'both',
                        quick_buy_compact: section.settings.enable_quick_buy_compact,
                        enable_quick_buy_desktop: section.settings.enable_quick_buy_desktop,
                        enable_quick_buy_mobile: section.settings.enable_quick_buy_mobile,
                        enable_quick_buy_qty_selector: section.settings.enable_quick_buy_qty_selector,
                        enable_quick_buy_drawer: section.settings.enable_quick_buy_drawer,
                        enable_color_picker: section.settings.enable_color_picker
                        sizes: image_sizes
                      -%}
                    {%- endfor -%}
                  </ul>
                {%- endif -%}
                {%- if pages.size > 0 -%}
                  <hr>
                  {%- for page in pages -%}
                    <div>
                      <header>
                        <h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
                      </header>
                      {{ page.content | strip_html | truncatewords: 50 }}
                      </br><a href="{{ page.url }}" class="strong">{{ 'general.read_more.read_more' | t }} <i aria-hidden="true" class="icon-chevron-right"></i></a>
                    </div>
                    {% unless forloop.last and articles.size == 0 %}
                      <hr>
                    {% endunless %}
                  {%- endfor -%}
                {%- endif -%}
                {%- if articles.size > 0 -%}
                  {%- if pages.size == 0 -%}<hr>{%- endif -%}
                  <ul class="l4ne">
                    {%- for article in articles -%}
                      {%- render 'article-item',
                        article: article, show_excerpt: section.settings.show_excerpt, show_image: section.settings.show_image, show_date: section.settings.show_date, show_author: section.settings.show_author, show_link: section.settings.show_link_post, button_color_palette: section.settings.button_color_palette_post
                      -%}
                    {%- endfor -%}
                  </ul>
                {%- endif -%}
              </div>
              {% render 'pagination',
                paginate: paginate,
                pagination_type: section.settings.pagination_type,
                show_amount: section.settings.show_amount_of_search_results
              %}
          {% endpaginate %}
      {%- endcase -%}
    {%- endfor -%}
  {%- if show_filters_and_menu -%}</div>{%- endif -%}
  {% if show_filters_and_menu %}
    <aside>
      {%- render 'filters-sorting',
        display: 'filters',
        show_filters: show_filters,
        filters: search.filters,
        quick_links: quick_links,
        filters_show_more_limit: section.settings.filters_show_more_limit
      -%}
    </aside>
  {% endif %}
</div>

Where should I add this specific code <input type="hidden" name="type" value="product'> ? Or if I should be using that code in the liquid file?

 

I'm very new to this (so the usage of terms may be wrong - so forgive me for this) and coding isn't exactly my niche so I would need any help with this. 

 

Thanks!

Accepted Solution (1)

Dan-From-Ryviu
Shopify Partner
9668 1936 1971

This is an accepted solution.

Hi @TatiGGG 

You can do that if you install Shopify Search and Discovery app Screenshot 2024-09-25 at 10.00.40.png

- Helpful? Like and Accept solution! Support me! Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

View solution in original post

Replies 3 (3)

Dan-From-Ryviu
Shopify Partner
9668 1936 1971

This is an accepted solution.

Hi @TatiGGG 

You can do that if you install Shopify Search and Discovery app Screenshot 2024-09-25 at 10.00.40.png

- Helpful? Like and Accept solution! Support me! Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

TatiGGG
Visitor
3 0 0

I didn't realise I could do it here. Did this and now it works! Thanks for guiding 😊

BSSCommerce-B2B
Shopify Partner
1780 546 605

@TatiGGG, try removing this one in your code

BSSCommerceB2B_0-1727233447971.png

 

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now