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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.