Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Add Defined Metafields Through API

Yoseo2024
Shopify Partner
2 0 0

I want to add metafields as specifications for the products in the store. 

I added metafields as below

 

namespace: "specs", 

key : [name of spec (ex. screen resolution)],

value: [value of screen resolution]

 

When I did this I was able to display the specifications in the product page as

 

{% for metafield in product.metafields.specs %}
<p>{{ metafield.first }}: {{ metafield.last }}</p>
{% endfor %}

 

but I was not able to use them for filtering because they were not defined. And I was unable to define them through the Shopify Admin because they had specials chars (spaces). 

Then I tried to add the key as a handle, with dashed instead of spaces and no more brackets, and added one more field to the metafields as description - that was the name of the spec with spaces and so on - however I can't display the metafield.description value. 

 

Any idea how can I add the metafields already defined, or to display the description? 

 

Thank you guys! 

Replies 2 (2)

Liam
Shopify Staff
2677 288 734

Hi Yoseo2024,

 

 If there are no special characters being used, are the values of the metafields appearing as expected?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Yoseo2024
Shopify Partner
2 0 0

Hi Liam, 

 

I tried that, the metafields are still not appearing as Defined already. 

I guess what I'm actually looking for is like a guide or how are Definitions and Metafields work. Can I add one definition and more metafields that are somehow related to that definition and more products?