How to Update an ACF Field Name Without Losing the Data

Advanced Custom Fields (ACF)

Are you using ACF (Advanced Custom Fields) and have the need to change the field name, but then you discover that it makes all the data disappear?

Since ACF uses the field name as the meta key to save and retrieve data, it makes it seem impossible to change.  You may consider changing only the label and leaving the field name alone.

However, in some cases, changing the name is needed.  If you’re in that boat, I’ve got good news.  It is possible to migrate all your post meta data to the new meta key.

In this post, I’ll show you exactly how to run a couple SQL statements on your database to migrate all the post meta data from the old key to the new key.

Backup Your Database

Whenever you are running database scripts, it is very easy to make a mistake and you can really mess up your site.  Make sure you take a backup.  You can use the UpdraftPlus Backup plugin, or you can export your database right from phpMyAdmin.

Don’t blame me if you mess up and didn’t take a backup!

Run These SQL Statements to Migrate Your ACF Data

Log in to your hosting control panel to access phpMyAdmin, the web interface for managing your MySQL database which WordPress runs on.

Click on your database on the left site, and then click the SQL tab at the top.

Note: in the following instructions, I’m using “wp_” as my table prefix.  If your WordPress installation uses a different database table prefix from the standard “wp_”, then use your prefix instead.

Get Your ACF Field’s Reference Key

ACF fields have a reference key that starts with “field_” followed by random letters and numbers.  Run this SELECT statement to find that reference key.

SELECT * FROM `wp_postmeta` WHERE meta_key LIKE '%old_field_name%'

You should see something like this.

In my example, the “old_field_name” is “video_url”.  You will also see 2 meta key/value records for each post_id.  One will have the meta_key exactly like you typed it with the meta_value that was entered in that ACF field.  The other record will have an underscore before the meta_key and its meta_value is the ACF reference key you’re looking for.  Take note of that reference key.

Migrate Your ACF Post Meta Data

Now, run the following UPDATE SQL script which will actually change the meta key (field name) from the old one to the new one.  Make sure to replace the following placeholder values with your own.

  • new_field_name
  • old_field_name
  • my_post_type = set this to the post type that you’re using your ACF field group with.  If you’re using it for blog posts, then your post type should be “post”
UPDATE `wp_postmeta` as m 
JOIN `wp_posts` as p ON m.post_id = p.ID 
SET m.meta_key = 'new_field_name' 
WHERE m.meta_key = 'old_field_name' 
AND p.post_type = 'my_post_type'

Migrate Your ACF Field Reference Key Post Meta Records

Now, run the following UPDATE statement that will update all of those records with meta keys that start with an underscore and have the meta key with our field’s reference key.

Here are the placeholders you will need to change out.

  • _new_field_name = should be your new field name with an underscore in front
  • field_5af0d933478b4 = should be the reference key that you took note of earlier with the SELECT statement
  • my_post_type = should be the same post type you used in the previous UPDATE statement
UPDATE `wp_postmeta` as m 
JOIN `wp_posts` as p ON m.post_id = p.ID 
SET m.meta_key = '_new_field_name' 
WHERE m.meta_value = 'field_5af0d933478b4' 
AND p.post_type = 'my_post_type'

All Done

That should be it.  You should now see your old data showing up in your ACF fields with the new field name.

If you have any questions or need help, let me know in the comments below.  Thanks!

Notify of

Most Voted
Newest Oldest
Inline Feedbacks
View all comments
1 year ago

Not perfect, but I found this to work like a charm for ACF field that are in groups (where the meta key looks like this: field_subfield).

UPDATE wp_postmeta
SET meta_key = REPLACE(meta_key, 'old_str', 'new_str')
WHERE meta_key LIKE '%old_str%' 
15 days ago
Reply to  Hélène

Hi, This is so nice to me!!
I have to change subfield name, and I did it!

// step 1: change repeater parent name
UPDATE wp_postmeta
SET meta_key = REPLACE(meta_key, 'repeater_old_str', 'repeater_new_str')
WHERE meta_key LIKE '%repeater_old_str%'

// step 2: change repeater subfield name
UPDATE wp_postmeta
SET meta_key = REPLACE(meta_key, 'subfield_old_str', 'subfield_new_str')
WHERE meta_key REGEXP 'repeater_new_str_(.)_subfield_old_str'

// step3: update name filed in ACF Admin panel.

Thank you so much!

2 years ago

Thank you, Nathan, for posting this. It really helped me a lot and the whole migration I had to do went just fine.

1 year ago

Thank you for this. Very helpful. How would you modify the UPDATE statements for user meta fields?

1 year ago

With the SQL query I write the code in and then click the ‘Go’ button. Is that it?

I use the post type ‘attachment’ as the ACF fields are set to media attachments.

Does it work for sub fields in a Repeater ACF field.

7 months ago

A slightly complicated case. I have a load of meta data that I want to convert to ACF. The reference key is missing so how do change your second UPDATE into an INSERT?