Support

Account

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.