# Collections with metafields

[Collections](https://help.shopify.com/en/manual/products/collections/create-collection.md) can have selection conditions to automatically include matching products or variants. Each **Products** or **Variants** [source](https://help.shopify.com/en/manual/products/collections/create-collection.md#product-sources) in a collection has a [limit of 60 condition values](https://help.shopify.com/en/manual/products/collections/conditions.md#condition-limits). You can specify if products or variants need to meet all conditions or any condition to be included in the collection. You can use metafield data as part of the conditions to give you more specific control of your collections.

Complete the following actions before you create a collection condition using metafields:

* [Add in your metafield definitions](https://help.shopify.com/en/manual/custom-data/metafields/metafield-definitions.md).
* [Make your metafield definitions available as collection conditions](https://help.shopify.com/en/manual/custom-data/metafields/collections.md#activating-collections).
* [Add the values to your products or variants](https://help.shopify.com/en/manual/custom-data/metafields/adding-values-to-metafields.md).
* To have category metafield conditions narrow collections to specific variants, [connect the category metafield to a product option](https://help.shopify.com/en/manual/custom-data/metafields/category-metafields/using-category-metafields.md#step-three).

## Benefits of using metafield data in collection conditions

Collection conditions with metafields can help you create more precise automated collections, when you need to use structured product or variant information. In comparison, [tags](https://help.shopify.com/en/manual/products/collections/conditions.md#tags) assigned directly to products are useful when you need a simple label or grouping method. For example, you might use tags such as `sale`, `fragile`, or `vip` to group products for internal filtering or broad segmentation.

Metafields are useful when you need to store a specific attribute and value in a consistent format. For example, you might create a product metafield for `material` with the value `cotton`, or a variant metafield for `fabric` with the value `linen`. You can then use those metafields as automated collection conditions, such as including products that have at least one variant where the `fabric` is `linen`.

Because metafields are part of your data model, you can integrate this same data across Shopify, such as your online store. You can use metafields to be more specific in your collections. You can create metafield definitions for color, and then create a collection that only pulls in products that have the color value you want for the collection. You can create a metafield definition that is for fulfillment urgency, and then create a collection that only pulls in products that are marked with an urgent fulfillment value. Metafields provide more flexibility and structure than tags.

## Considerations for using metafield data in collection conditions

Before using metafields to define conditions for collections, review the following considerations:

* You can turn on the [**Use as a condition in collections**](https://help.shopify.com/en/manual/custom-data/options.md) option for a maximum of 128 product metafield definitions and 128 variant metafield definitions.
* You can't delete a metafield definition until the collection is updated to remove the metafield definition as a condition.
* When using a metafield as a condition for including variants in a collection, the metafield must be connected to a linked variant option in order for the customer-facing collection filters and swatches to filter down to only the included variants.

### Metafield definitions and supported conditions {#metafield-definitions-and-supported-conditions}

Only certain product and variant metafield definitions are supported with specific conditions.

<table>
  <caption>Metafield definitions and supported conditions for collections</caption>
  <thead>
     <tr>
        <th scope="col">Metafield definition type</th>
        <th scope="col">Supported conditions</th>
     </tr>
  </thead>
  <tbody>
     <tr>
        <td scope="row">True or false</td>
        <td>equals</td>
     </tr>
     <tr>
        <td scope="row">Integer</td>
        <td>equals<br>greater than<br>less than</td>
     </tr>
     <tr>
        <td scope="row">Decimal</td>
        <td>equals<br>greater than<br>less than</td>
     </tr>
     <tr>
        <td scope="row">Rating</td>
        <td>equals<br>greater than<br>less than</td>
     </tr>
     <tr>
        <td scope="row">Single line text (one value)</td>
        <td>equals</td>
     </tr>
     <tr>
        <td scope="row">Single line text (list of values)</td>
        <td>includes</td>
     </tr>
     <tr>
        <td scope="row">Metaobject reference (one value)</td>
        <td>equals</td>
     </tr>
     <tr>
        <td scope="row">Metaobject reference (list of values)</td>
        <td>includes</td>
     </tr>
  </tbody>
</table>

The condition that a single line text or metaobject reference definition supports depends on whether it accepts one value or a list of values. Learn more about [metafield lists](https://help.shopify.com/en/manual/custom-data/metafields/metafield-definitions/metafield-lists.md). The `includes` condition matches a product or variant when the condition value is one of the values in its metafield list.

In your Shopify admin, the `equals` and `includes` conditions for these definitions are labeled as follows:

* On the collection page, in a **Products** or **Variants** source, both conditions are labeled **is**. The **is** label is fixed text rather than a drop-down menu, because these definitions support only one condition each.
* In the **Conditions** column on the **Collections** page, the label is **is equal to** for a one-value definition and **includes** for a list-of-values definition. Each entry lists the metafield definition's name, the label, and then the condition values. For example, `Material includes Cotton`.

## Making a metafield definition available as a collection condition {#activating-collections}

To use a metafield definition for collections, you need to turn on **Use as a condition in collections** for the metafield definition. This option is available only for product and variant metafield definitions with a [supported metafield definition type](https://help.shopify.com/en/manual/custom-data/metafields/collections.md#metafield-definitions-and-supported-conditions). Learn more about [creating custom metafield definitions](https://help.shopify.com/en/manual/custom-data/metafields/metafield-definitions.md).

<aside class="note"><h4>Note</h4><p>Activating a metafield definition for collections makes it available as a collection condition. To narrow a collection to specific variants using a category metafield condition, the related product option also needs to be connected to that category metafield.</p>
<p>For example, if the <strong>Color</strong> option is connected to the <strong>Color</strong> category metafield, then a collection source that&#39;s set to <strong>Variants</strong>, and with the condition <code>Color is red</code>, includes only variants with the <code>red</code> color option value.</p>
<p>If an option isn&#39;t connected to a category metafield, then a condition for that metafield can still match the product, but the condition doesn&#39;t narrow the collection to specific variants for that option.</p>
</aside>

#### Steps:

<div class="sections"><details open><summary id="desktop">Desktop</summary><ol>
<li><p>From your Shopify admin, go to <strong>Settings</strong> &gt; <a href="https://admin.shopify.com/settings/custom_data"><strong>Metafields and metaobjects</strong></a>.</p>
</li>
<li><p>Depending on the metafield definition that you want to use for collections, select either <strong>Products</strong> or <strong>Variants</strong>.</p>
</li>
<li><p>Click the metafield definition that you want to use for your collection.</p>
</li>
<li><p>In the <strong>Options</strong> section, turn on <strong>Use as a condition in collections</strong>.</p>
</li>
<li><p>Click <strong>Save</strong>.</p>
</li>
</ol>
</details><details><summary id="mobile">Mobile</summary><ol>
<li><p>From the <a href="https://www.shopify.com/install/detect">Shopify app</a>, tap <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/MenuIcon.svg" alt="Menu" class="admin-icon" />, and then tap <img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/SettingsIcon.svg" alt="Settings" class="admin-icon" /> <strong>Settings</strong>.</p>
</li>
<li><p>In the <strong>Store settings</strong> section, tap <strong>Metafields and metaobjects</strong>.</p>
</li>
<li><p>Depending on the metafield definition that you want to use for collections, select either <strong>Products</strong> or <strong>Variants</strong>.</p>
</li>
<li><p>Tap the metafield definition that you want to use for your collection.</p>
</li>
<li><p>In the <strong>Options</strong> section, turn on <strong>Use as a condition in collections</strong>.</p>
</li>
<li><p>Tap <strong>Save</strong> or <strong>&#10003;</strong>.</p>
</li>
</ol>
</details></div>

## Add metafield definition conditions to a collection

You can add a condition to include products or variants with a particular [metafield](https://help.shopify.com/en/manual/custom-data/metafields.md). You can use product metafields or variant metafields. For example, you can set up a condition that selects products with the metafield definition `Color` and the value `#FF0000`.

#### Steps:

1. From your Shopify admin, go to **Products** > [**Collections**](https://admin.shopify.com/collections).

2. Click a collection that you want to add products to.
3. In a **Products** source or a **Variants** source, click **<img src="https://cdn.shopify.com/shopifycloud/help-center/manual/admin-icons/PlusCircleIcon.svg" alt="Add" class="admin-icon" />Add condition** > **Metafield**.
4. Select **Color** as the metafield definition.
5. Click the **Select value** field, and then select **#FF0000**.
