How can I dynamically add a post to a custom post type which uses a custom field?

I’m not sur but I think you had (will probalby help other people as the guy who I was 1hour ago)/have same problem that I just resolve.

You have a custom field and you want to manage an User type field in it ?!

Well, everyone know UPDATE_FIELD, but what I didn’t know that if you want to add a user, u just have to give the ID, and not the array structure taht print out when u get this fild (nickname, nicename, displayname…)

update_field(‘yourfieldkey’, arrayofyouruserID, theidofyourrelatedpost);

My code to manage (add/delete) new user in relation with the post :

/* remake the memberassigned list*/
$ticket_users = get_field('tickets_assignedto', $thispost_id);
$new_assignedmembersID = array();
if ( $ticket_users != '' ) {
   foreach ($ticket_users as $ticket_user) {
       if ( $ticket_user['ID'] != $member_id ) {
            $new_assignedmembersID[] = $ticket_user['ID'];
       } 
   }
}

if ( $byeorhi == 'member_unassigned') {
    $new_assignedmembersID[] = $member_id;
}

update_field('field_54b8d8b213289',  $new_assignedmembersID,  $thispost_id);

tech