Make metafield vaules come up in the search bar?

darkthrone
Shopify Partner
21 0 4

Hello,

I have some metafield values in my products on my shopify store. Is there any way to make the products show up in the search bar for them? I wrongly assumed this was something Shopify had built into it. 

Replies 2 (2)

EcomGraduates
Shopify Partner
588 48 79

Hello there  

 

Yes, it is possible to make the products show up in the search bar for metafield values in Shopify. However, it requires some customization to your Shopify theme.

To make the products show up in the search bar for metafield values, you can follow these steps:

  1. Create a new search input field in your Shopify theme. This can be done by modifying the theme's header or search template file.

  2. Use Liquid code to query the product metafields and search for any matches based on the search input.

 

{% for product in collections.all.products %}
  {% assign metafields = product.metafields %}
  {% for metafield in metafields %}
    {% if metafield.value contains search %}
      <a href="{{ product.url }}">{{ product.title }}</a>
    {% endif %}
  {% endfor %}
{% endfor %}

 

 

  1. Customize the code as needed to match your theme and search requirements. You can modify the search input field styling, search algorithm, and display format for the search results.

  2. Save the changes to your Shopify theme and preview the search functionality to ensure that it is working correctly.

 

Wayzn
Visitor
2 0 1

IS there a similar approach that can be used to make order metafields searchable in the Shopify Admin main search or Orders search so we can find an order based on the value of one of its custom metafields?