Home Forums ACF PRO Not Migrating Data When Fields Updated?


Not Migrating Data When Fields Updated?

  • Hi Folks,

    I recently changed the name of a field fields in a field group. I was surprised when I navigated to a page that used these fields to find that the fields were no longer passing any data.

    I looked at the database and realized that while the fields have been updated in ACF and new data would go into the appropriately named postmeta, the existing data was not migrated to the new field names.

    If I have a field named “my_awesome_field” and I have created a post which utilizes this custom field and I have given the field the value “Hey, I’m awesome!” we end up with postmeta that has a meta_key of my_awesome_field and then a meta_value with “Hey, I’m awesome!”

    Now, lets say I want to change my field name to “our_awesome_field” (you know, sharing is caring). After I have done so when I add a post that uses this field the data will be placed into meta_value attached to a meta_key called our_awesome_field. Great! But all of my existing posts that have values for my_awesome_field will no longer show up because they no longer have the correct meta key associated with them.


    I realize that I could do an if..then to check whether a my_awesome_field existed and use that value in cases where our_awesome_field does not, but I’m trying to reduce unnecessary verbosity, not increase it.



  • This is the way that ACF works. ACF is basically just a very big wrapper for WP functions like get_post_meta(), update_post_meta(), get_option(), update_option(), and other similar functions.

    If you created your own meta boxes without ACF and created fields with a “meta_key”, if you later decided to change that meta_key to something else, any existing values would be stored under the old meta key and not the new one.

    In either case, if you decide to rename your fields then the only solution is to do a search and replace in the database to rename all of the “meta_key”s to the new name.

    It’s also really easy to say that if you change a field name that all the old values should be updated, but it’s really not that easy to do. It’s further complicated by the fact that I could have a field named “field_X” in two different field groups associated with two different post types, now you need to update some of the field names and leave the others alone.

    In the end, it really doesn’t matter what the “field name” is, no one except the developer will ever see it, so renaming them, except for my own reasons, really isn’t important. I could have fields named “lajdslkf”, “ldalsudsdh”, and “nhdosaoh”. Not very easy to work with, but no one but me will see them, or the poor developer that ends up working on it.

  • Thanks John. That is what I suspected, but before I went doing any more manual mucking, I figured I’d make sure there wasn’t anything available to handle it. 🙂

  • I’ve often thought about creating something that can manage changing field names, as well as removing data when a field is removed, but I can never find the time for it and it’s low on my personal priority list. I’ve also been very careful about making sure that I don’t run into a situation where it necessary…

    although, I do have a site that I need to modify right now, not the same problem, but similar. I created a select field for a client with 3 possible values and now they want to change one of those values which means that I have to go digging through the database and create a some type of query to alter the values stored in more than 5K product posts.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Not Migrating Data When Fields Updated?’ is closed to new replies.