Problem with repeater field:
File field created. Different posts have been created. Then I decided to change the acf ‘file’ field to ‘repeater’ with a ‘file’ field inside. My problem is that on previously created ads: the repeater field create a back office loop when there are only 2 files added.
The problem is that your old field and new field has the same name. The old field stored a post ID value of the attachment file, let’s say that ID is 1000.
For a repeater field ACF stores several values, the values stored for the repeater itself is then number of rows in the repeater. When ACF get’s this value it creates that number of rows.
1) You need to use a different name for the repeater than you used for the original field
2) You cannot transfer existing values from your original field into rows of the repeater, at least not without a lot of work.
As a side note, I’m going to have to do something similar. I have a client that is requesting that fields that used to have a single value be changed to fields that can have multiple values with added information for each value and I’m going to need to use repeaters for this.
I cannot give specifics, because I have not worked on this yet, but I can tell you what I plan to do.
1) I will create a new repeater field with a new name
2) I will use an acf/prepare_field filter to never show the old field. The field will still exist, but will not be editable by the client. https://www.advancedcustomfields.com/resources/acf-prepare_field/
3) When a post is loaded in the admin to edit I will have an acf/load_value filter for the new repeater field https://www.advancedcustomfields.com/resources/acf-load_value/. This filter will check the old field to see if it has a value and if it does it will transfer this value to the repeater.
4) When the post is saved I will have an acf/save_post action https://www.advancedcustomfields.com/resources/acf-save_post/ that will delete any values in the old field.
5) On the front end I will use the repeater and I will also check the old field for any values and I’ll have different logic and do different things based on where the values are stored.
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!
© 2019 Advanced Custom Fields. Subscribe