You need to create an acf/save_post action. You need to set the priority of your action < 10 so that it runs before ACF saves the value.
You can get the new value of the field from
field_XXXXXXX is the field key of your relationship field.
You can get the old value from the database at this point using
get_field('relationship_field_name', $post_id, false), the 3rd argument in the call tells acf not to format the value
In both cases the value will be an array of post IDs. You then need to compare the two arrays and add or remove terms from each post based on that comparison using wp_add_object_terms().
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!
© 2022 Advanced Custom Fields.