Support

Account

Home Forums General Issues How to update (add to) a user field via php Reply To: How to update (add to) a user field via php

  • The user field holds an array of user IDs.

    If you want to add a user ID to the field that already has values.

    
    // get the user field without formatting
    $users = get_field('user_field', $post_id, false);
    // test to see if empty
    if (empty($users)) {
      $users = array();
    }
    // add a user
    $users[] = $new_user_id;
    // use field key to update field
    // it will not update using field name
    // if it did not already have a value
    update_field('field_XXXXXXX', $users, $post_id);