Support

Account

Home Forums General Issues Unable to write multiple values ACF user field back to DB Reply To: Unable to write multiple values ACF user field back to DB

  • It is not 100% clear by your question what type of field you’re using. If you are working with a user field, a user field stores only the User ID values in and array. The same is true of a relationship field if that is what you’re using. When you use update_field() you need to supply ACF with the value as it needs to be stored, in this case an array of ID values.

    You can get the current value unformatted by using the 3rd parameter.

    
    $current_mentees = get_field('current_mentees', $mentor_post_id, false);
    

    then you can add a new ID to the array

    
    $current_mentees[] = 125; // or whatever code your using to get the ID to add
    

    then you update the field

    
    update_field('current_mentees' , $current_mentees , $mentor_post_id);