Home › Forums › Add-ons › Repeater Field › Is there no way to uniquely identify an repeater field entry? › Reply To: Is there no way to uniquely identify an repeater field entry?
My burned earth fallback is whenever the acf/save_post hook is called with the repeater field present, just delete all rows with that post ID and then put them all back in again which will ensure that there is absolute parity between the fields on the wp_postmeta table and my custom, but there has to be a better way.
When dealing with copying repeaters your “burned earth” method is usually what I do.
A unique ID field for each repeater row like @jarvis suggested could be used as. Create another field in the repeater to contain the unique ID, use an acf/prepare_field filter to make the field read only generate a value for the field if it does not have a value. But this won’t solve the problem of figuring out what you need to delete in the other table.
To not use the burned earth method requires using a priority of < 10 on the acf/save_post action, then comparing what is in $_POST[‘acf’] (new values) with what is returned by get_field(), get_sub_field(), one row at a time to see what has changed. This is why, unless there is some pressing reason not to, that I use the burned earth method.
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!