> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Add a Field to a Collection

## Article: Add a Field to a Collection

## Article Link: https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/add-a-field-to-a-collection.md

## Article Content:

# Add a Field to a Collection

Add a [field](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/about-collection-fields.md) to an existing [collection](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/about-collections.md) on a Studio Two site, so its items can store another kind of value. This article shows how to add a field with a script from the **Wix Data** view in the Code tab.

You can also add a field in the [CMS dashboard](https://support.wix.com/en/article/cms-formerly-content-manager-adding-a-field-to-a-collection). To add one from site code, call [Create Data Collection Field](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections/create-data-collection-field?apiView=SDK.md) in backend code with [elevated permissions](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/about-the-data-api.md#permissions).

## Step 1 | Open an Add Field script

**Add Field** opens a script that already contains a template field definition for the collection.

To open an Add Field script:

1. In the Studio Two editor, open the **Code** tab.
2. In the row of icons at the top of the sidebar, click the database icon to open the **Wix Data** view.

   ![The top of the Code tab's sidebar, with the Wix Data icon highlighted and the Wix Data view open](https://wixmp-833713b177cebf373f611808.wixmp.com/images/983b41f68c3cda4c4e10eb8deb25d301.png)

3. Right-click the collection and select **Add Field**. A script opens in a new tab.

The script isn't part of the site's code, and you choose when to run it.

## Step 2 | Define the field

The template script looks like this, with the collection's ID already filled in:

```javascript
collections.createDataCollectionField("Listings", {
  field: {
    key: "<choose a key>",
    displayName: "<choose a display name>",
    type: "TEXT",
  },
});
```

To define the field:

1. Replace `<choose a key>` with the [field ID](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/about-collection-fields.md#field-ids) that code uses.
2. Replace `<choose a display name>` with the name that the CMS dashboard shows.
3. Set `type` to the [field type](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/create-a-collection.md#field-types).

This example adds a `bathrooms` number field to a `Listings` collection:

```javascript
collections.createDataCollectionField("Listings", {
  field: {
    key: "bathrooms",
    displayName: "Bathrooms",
    type: "NUMBER",
  },
});
```

## Step 3 | Run the script

To run the script, click the play icon, **Wix Data: Run Query**, at the top right of the script tab. The response opens in a `result.json` tab and shows the updated collection.

## Step 4 | Check the field

To check the field:

1. In the **Wix Data** view, click **Refresh Collections**.
2. Expand the collection. The new field is listed as `<fieldId>: <TYPE> ('<Display name>')`.

## See also

- [About Collection Fields](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/about-collection-fields.md)
- [Create a Collection](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/create-a-collection.md)
- [Find Collection and Field IDs](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/find-collection-and-field-ids.md)