Displaying filtered metaobject entries on default product page (metafields)

Topic summary

A developer is building a dynamic influencer section for Shopify product pages using metaobjects and metafields. They created an “influencer” metaobject type with a products field (list of products) and connected influencers to products bidirectionally—both through product metafields and the metaobject’s product list.

The core issue: The conditional statement {% if influencer.products contains product %} fails to filter entries correctly. Without this condition, all influencer entries display; with it, none appear.

Additional context:

  • The developer wants to avoid using Shopify’s customizer due to design requirements and error messages appearing on products without influencer data
  • The code loops through shop.metaobjects.influencer.values to display influencer cards
  • The posted code snippet appears corrupted/reversed in formatting, making detailed debugging difficult

The question seeks help identifying why the contains logic isn’t working as expected to filter influencers by associated product.

Summarized with AI on November 6. AI used: claude-sonnet-4-5-20250929.

On my default product page, I want to display a dynamic influencer section, in which influencers connected to a specific product would be shown. In order to do this, I created a metaobject called influencer (type: influencer) and a metafield with the same name (key: custom.influencer). To display the entries, I wrote the piece of code below. The influencer object accepts product entries in influencer.products (list of products).

I connected my entries both via metafield influencer in products as well as in the metaobject under influencer.products. I have been experiencing difficulties with my if statement {% if influencer.products contains product %} (see code below). My intention was to only display the influencers who are connected to this specific product. Without the if statement all the entries are displayed, with it - none.

I do not really want to use the customizer for it - not only because of a specific design I want to achieve, but also because of not all products having influencer entries (when the customized section is empty, it displays an error message on the product page).

Does anyone know what the issue with my if statement logic might be?

{% if product.metafields.custom.influencer != blank %}

Influencers

Experience our products in action.

{% for influencer in shop.metaobjects.influencer.values %} **{% if influencer.products contains product %}**
Influencer

{{ influencer.name }}

{{ influencer.influencer_short_description }}

{% endif %} {% endfor %}
{% endif %}