Support

Account

Home Forums ACF PRO Data Migration of Clone Fields Reply To: Data Migration of Clone Fields

  • @jgregory we did not figure out a solid migration plan. We found a work around, although I think there should be a better solution, of publishing our clone fields and renaming them the same name as the existing cloned field name. This allowed us to keep the data intact.

    So basically, we had several Field Groups that were a tab layout. To keep the data and have then show in GraphQL, we had to get the existing name of the clone field in the tab, publish the field being used for cloning and rename it to what the field name was in the tab.

    I did come up with some sort of db migration, but it got confusing and I wasn’t the only one working on the project so we ended up scrapping it and going this way, but here is what I came up with if you wanted to go the go the db route.

    For example, to search for Header Secondary you would use:

    SELECT * FROMwp_postmetaWHERE meta_key like '%_header_secondary%'

    this will return all keys for that. But we still need to find the specific one for the field group you are working on. To do that we need to find a post that is using that group and get it’s ID and then we can run:

    SELECT * FROMwp_postmetaWHERE post_id = {id} AND meta_key like '%header_secondary%'

    Now that you have both key and value for a post we can run an update sql statement. There will be 2:

    We are migrating old field name to new field
    UPDATEwp_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 = ‘page’`

    We are migrating old field value to new field name.

    This is how we keep the data this is what is mapped to the wp_posts table
    UPDATE <code>wp_postmeta</code> as m 
    JOIN <code>wp_posts</code> 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 = 'page'

    I did run some tests with this and it did work. Depending on how many Fields you have though this could be a long process. I was thinking about maybe righting up a php script that could automate this but I don’t have much time to work on it.