Support

Account

Home Forums Backend Issues (wp-admin) update_field() with field type User Reply To: update_field() with field type User

  • Get the value of the field without formatting and supply the post ID of the post that you want to update. Get Field: https://www.advancedcustomfields.com/resources/get_field/; Update Field: https://www.advancedcustomfields.com/resources/update_field/

    
    // $post_id is the ID of the post you want to update
    // 3rd arg == false tells ACF not to format the value
    // $users will == an array or user IDs
    $users = get_field('user_field_name', $post_id, false);
    
    // add the users ID to the array
    $users[] = $new_user_id_to_add;
    
    // update the field
    // $selector == the field key of the field to update
    update_field($selector, $users, $post_id);