Migrating metafields to a definition
If you want to add validation rules to an existing set of metafields, then you can migrate your metafields to a definition. When you create a custom definition for existing sets of metafields, the validation rules that you specify prevent you or your apps from adding invalid values.
You migrate your metafields by creating a custom definition for a set of metafields with a particularnamespace and key. You can migrate metafields to most content types, except for file, reference, and true or false. For more information about creating custom definitions, refer to the following:
You can only add definitions for sets of metafields that have a namespace and key with the correct format. If your namespace and key contains special characters, then you can't migrate that set of metafields to a definition.
Create a definition for sets of metafields that don't yet have a definition
- From your Shopify admin, go toSettings>Metafields.
- Select the part of your store that you want to add a metafield definition for. For example,Products.
- ClickMetafields without a definition, and then clickAdd definitionnext to the namespace and key that you want to add a definition for.
- Review theSample metafieldto determine the correct type and validation rules for the namespace and key. To display additional sample values, clickView more.
- Enter the following information for your metafield definition:
- In theNamefield, enter a name for your definition.
- Optional: In theDescriptionfield, enter a description for your metafield.
- ClickSelect content type, and then select the content type that best matches your metafield values from the list.
- Configure the content type and validation information by doing the following:
- If the content type has additional configuration options, then select the correct option for your metafield. For example, type of measurement.
- In theValidationsection, configure theAdditional rulesfor your definition.
- ClickSave.
- 检查验证results, and then clickSave and continue.
If any metafield values don’t match your new definition, then you need tofix your metafield values. After you save your definition, you're automatically redirected to the bulk editor to review and fix any validation errors.
Next steps after adding metafield definitions
After you add definitions for your metafields, you can do the following:
- Pin or unpin metafield definitionsto determine the order in which your metafields are displayed.
- Add values to metafieldsfor parts of your store.
- Connect your metafields to your themeto display them on your online store.