Home › Forums › Add-ons › Repeater Field › Override issue when repeater is populated both via backend and frontend
I use a repeater field for creating a visitor list:
First Name Last Name
---------------------------
1 John Miller
---------------------------
2 Tom Brown
---------------------------
3 Mike Smith
---------------------------
...
My field can be populated in two ways:
My problem:
So, my question is:
How can I prevent this? How can I check if new entries were added to the list before it is saved? I guess, I could use the acf/update_value filter or the acf/save_post action – but I don’t know how.
Thanks a lot,
Karl
I have not done this and I don’t know all the details but.
I would create an acf/save_post filter with a priority of 1 so that it runs before ACF saves the values. See details here https://www.advancedcustomfields.com/resources/acf-save_post/
In this filter I would somehow check the existing value against the submitted value and update the field as needed. This is where I don’t have the details. It would take a lot of testing to figure out how to accomplish it on both the front and back end.
When I was done I would unset any relevant field keys in $_POST[‘acf’]. Removing the submitted values will prevent ACF from updating those fields and undoing the work you did in the filter.
This is an issue when someone tries to edit both sides of a bidirectional relationship at the same time. I tell my clients not to do it. However, if there is no way to prevent this from happening then I’d have to work it out.
I have reconsidered my approach and came to the conclusion that it’s definitely not a good idea to make the list editable from both sides. Your answer was very helpful to me and confirmed my worries.
Thank you very much, John.
Karl
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!
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.