Home › Forums › General Issues › update_field on a relationship field › Reply To: update_field on a relationship field
To update an existing relationship field to add a value you first need to get the existing value without formatting and then add the new post ID to it.
// get current value
$value = get_field('relationship_field', $post_id, false);
// add new id to the array
$value[] = $inserted_post_id
// update the field
update_field('relationship_field', $value, $post_id);
To delete existing values in the current post
delete_field('some_field', $post_id);
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.