Home › Forums › General Issues › Assign a taxonomy term to items in Post Object › Reply To: Assign a taxonomy term to items in Post Object
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 $_POST['acf']['field_XXXXXXX']
where 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!
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.