<p>Select fields store selected options by their value, so changing the values will result in data loss the next time the entries are saved. You can solve this with <a href="https://craftcms.com/docs/4.x/extend/migrations.html" rel="nofollow noreferrer">migrations</a>.</p>
<p>One option is to change the values of the multi-select field, then write a migration that will replace the old values with the new ones in the database. If I recall correctly, multi-select fields store the selected options as JSON strings, so you'll probably need to iterate through all rows, decode the JSON, replace the old values with the new ones, encode the JSON again and save it back to the database.</p>
<p>If this doesn't work for any reason, you can also do this in two steps:</p>
<ol>
<li>Rename your existing field and append something like <code>_OLD</code> to the handle (i.e. <code>activeSites_OLD</code>) and use field conditions to hide it for all users except admins. Create a new field with the new option values and add it to all field layouts where the old fields are in use. Update your templates and modules to work with the new field values. Then write a migration that iterates through all entries and saves the correct values to the new field based on a mapping of the values from the old field. In the production environment, run this migration immediately after applying the project config (which creates the new field). This should happen automatically as part of your deployment if you follow the recommended <a href="https://craftcms.com/knowledge-base/deployment-best-practices" rel="nofollow noreferrer">deployment best practices</a>.</li>
<li>After you've checked that the migration succeeded and all entries have the correct data in the new fields, you can safely remove the old field from all field layouts and delete it.</li>
</ol>
<p>This two-step approach is a bit safer than manually modifying the database, since you can write your migration using high-level APIs, and the old data is still there in case anything goes wrong with the migration. Though, you should always create a full backup before deploying any changes to the production environment.</p>
<hr />
<p>As a side note, Craft recently added an option for sections to <a href="https://craftcms.com/docs/4.x/sites.html#propagating-entries-across-all-enabled-sites" rel="nofollow noreferrer">manually select which sites an entry should be propagated to</a>. This might be a better solution than a custom multi-select field, make sure to test if this works for your use-case.</p>

CC BY-SA 4.0
2023-04-10T12:16:17.250Z
2023-04-10T12:16:17.250Z
MoritzLost
<p>Is there a way to make a change to the value of a multi-select field, leaving the labels intact, and update the field across all the entries while preserving the current selections?<br />
I have a multi-select field used to denote where an entry should exist on a multi-site from a setup that predates Crafts native support of multi-site. The values of each option contains the handle used for the old multi-site(i.e. siteUs, siteCn, siteSg, siteAu etc). The new site handles( siteUS, siteCN, siteSG, siteASTL) have a slightly different naming pattern. The ask was to propagate entries to the new multi-sites based on this fields values.</p>

<entry><field><multi-site>
Populate changes to a multi-select field across all entries without losing current values
# Populate changes to a multi-select field across all entries without losing current values

(Asked by: username_0 on 2023-04-07)

Is there a way to make a change to the value of a multi-select field, leaving the labels intact, and update the field across all the entries while preserving the current selections?  
I have a multi-select field used to denote where an entry should exist on a multi-site from a setup that predates Crafts native support of multi-site. The values of each option contains the handle used for the old multi-site(i.e. siteUs, siteCn, siteSg, siteAu etc). The new site handles( siteUS, siteCN, siteSG, siteASTL) have a slightly different naming pattern. The ask was to propagate entries to the new multi-sites based on this fields values.

**Tags:** entry, field, multi-site


---

## 1 answers

### Answer by username_1 on 2023-04-10. Score: 2 | Accepted answer

Select fields store selected options by their value, so changing the values will result in data loss the next time the entries are saved. You can solve this with [migrations](https://craftcms.com/docs/4.x/extend/migrations.html).

One option is to change the values of the multi-select field, then write a migration that will replace the old values with the new ones in the database. If I recall correctly, multi-select fields store the selected options as JSON strings, so you'll probably need to iterate through all rows, decode the JSON, replace the old values with the new ones, encode the JSON again and save it back to the database.

If this doesn't work for any reason, you can also do this in two steps:

1. Rename your existing field and append something like `_OLD` to the handle (i.e. `activeSites_OLD`) and use field conditions to hide it for all users except admins. Create a new field with the new option values and add it to all field layouts where the old fields are in use. Update your templates and modules to work with the new field values. Then write a migration that iterates through all entries and saves the correct values to the new field based on a mapping of the values from the old field. In the production environment, run this migration immediately after applying the project config (which creates the new field). This should happen automatically as part of your deployment if you follow the recommended [deployment best practices](https://craftcms.com/knowledge-base/deployment-best-practices).
2. After you've checked that the migration succeeded and all entries have the correct data in the new fields, you can safely remove the old field from all field layouts and delete it.

This two-step approach is a bit safer than manually modifying the database, since you can write your migration using high-level APIs, and the old data is still there in case anything goes wrong with the migration. Though, you should always create a full backup before deploying any changes to the production environment.

---

As a side note, Craft recently added an option for sections to [manually select which sites an entry should be propagated to](https://craftcms.com/docs/4.x/sites.html#propagating-entries-across-all-enabled-sites). This might be a better solution than a custom multi-select field, make sure to test if this works for your use-case.


---

