Home › Forums › General Issues › Resolving lost data when moving field to group? › Reply To: Resolving lost data when moving field to group?
The simple answer to your question is that this is extremely difficult to do without making many changes to the database. You have to find all of the fields in the DB and alter the meta key value to match the new name used by ACF.
What you would need to do is to do a query on to get all posts, then loop over the post, get the old field value using get_post_meta() (because ACF will not be able to find this field using get_field()) then use update_field() to update the value of the new group field. If you have many posts this is likely to fail do to timing out. It can be done directly in the database but this would be prone to errors if the old field name is not unique.
When I make interface changes of this nature I do the following
(this is a quick explanation as there is a lot of code that would be involved)
This allows you to alter the field setup without needing to alter all of the existing data and will transition the fields from old to new as a post is updated. If a post is never updated then it will continue to work indefinitely.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.