Home › Forums › Backend Issues (wp-admin) › How to automatically detach a file from a post (deleted via edit post)? › Reply To: How to automatically detach a file from a post (deleted via edit post)?
You need to create an acf/save_post action that runs at a priority of <10 so that it runs before ACF has updated the DB.
In this action you need to compare the old values with the new values.
The new values will be in a nested array in $_POST[‘acf’]. The old values can be retrieved using a have_rows() loop. Both values will be attachment IDs. You need to collect a list of both the old values and the new values, compare the lists and anything in the old values that is not in the new values you need to update the post_parent of the attachment to set it to 0 (zero).
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.