Home › Forums › Bug Reports › update_field on empty Relationship not working › Reply To: update_field on empty Relationship not working
Hi @rivage
So just to be clear, when you say “new entries” you mean selecting posts within the relationship field?
I think this is more an issue of how update_field works and how people expect it to work. Just like it sounds the function update_field are only capable of updating an existing meta value. When you have a new post (or where ever you placed the field) with nothing added to the field (nor anything previously added but now deleted) there is no meta key in the DB. So the update_field function fails.
What you can do instead is look at how the relationship-field saves the values to the DB. I’m fairly certain it’s just an array of IDs but take a look to be sure. Then you can use WP Core function update_post_meta instead and pass in values just like they would be saved by ACF.
Then it’ll work I’m sure.
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.