Home › Forums › Add-ons › Repeater Field › Convert Field to Repeater without Loosing Existing Data
Hi there! I feel like this topic must have been asked/covered before, but I searched all over and couldn’t find any existing topics.
I am using ACF so a client can upload a file to a custom post type. We already have about 120 entries/files uploaded. What I would like to do is convert the file field to a repeater so that multiple files can be uploaded without loosing the existing files. Is there any way to do this? Thanks!
I think you’d have to do in manually by creating a script to do the work.
You field, not as a repeater requires two postmeta entries
When you have a repeater this changes to
My suggestion would be to leave it as it is and create a new field for your repeater. Tell the client that on new posts to ignore the old field and use the new one, and when updating an old post to move the old images to the new field. Then in the front end use values from both fields in the display.
Similar to Robby, I’ve been faced with this a couple of times. What I would like to know is: Would it be possible, with ACF Pro, to have it so that if you drag an existing field into a repeater, ACF would update the corresponding saved data automatically on update?
I came across the same problem today (noticed i had repeaters with 1000s of rows) and stumbled upon this thread.
I created the following script to convert the data of a file field into a repeater. This worked when there was a file uploaded (field has data) and should be inserted into array of repeater on first position.
Use at your own risk! I’d advise to make database backup and test in local environment first.
To answer the question by @squarestarmedia
No, this is not possible. When you are editing a field group ACF does not know what data in the database is saved using the field. In addition to this, when the group is saved, ACF does not know that the field use to be a top level field and is now nested in a repeater (or visa-versa). Nor does in know if you’ve changed to location rules of the group.
The data stored for a field is related to a post or some other object.
The field group is not related to anything. The fields in the group are related to the group.
In order to associate the field to the data when getting or saving a post (or other object) ACF needs 2 important pieces of information the first is the post ID and the second is the field key. ACF has the field key when saving a field group, but it does not have the post IDS for every post the a value is saved to.
You must be logged in to reply to this topic.
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.