Home › Forums › Add-ons › Repeater Field › Multiple fields -> to repeater field with subs › Reply To: Multiple fields -> to repeater field with subs
When you move a field into a repeater you are effectively changing the field name. The old data is in the DB under the old name, for example "name"
, and you can continue to get the value using get_field('name')
however, this is no longer the real name of this field and you cannot get values added in the repeater in the same way. Your new repeater field needs to use a have_rows()
loop and use get_sub_field('name')
to get the values https://www.advancedcustomfields.com/resources/have_rows/
ACF does not move the content stored in existing fields when the field names are changed, or moved into or out of repeaters, which is basically the same thing. The reorganization changes the field names.
You would need to build code to do this moving and you would also need to build code to check it.
For example, in your template where you are showing these values you would need to do something like
if (have_rows('repeater')) {
// values have been added to the repeater
} else {
// nothing in repeater
// look in the old field names
}
In the admin you can use an acf/load_field filter on the repeater https://www.advancedcustomfields.com/resources/acf-load_field/. In this filter you can do the same checking. If the value of the field is empty then get the values from the old field and dynamically populate the first row of the repeater with the old values. You could also create an acf/save_post action https://www.advancedcustomfields.com/resources/acf-save_post/ that would delete the old values using delete_post_meta()
.
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.