Support

Account

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);