Support

Account

Home Forums General Issues Change user type field's return from array to ID, every CPT needs to be updated? Reply To: Change user type field's return from array to ID, every CPT needs to be updated?

  • A user field always holds an array of user IDs. This might change if you only allow one user to be selected, but I don’t think so. You must still loop over the even when you are returning IDs.

    
    $users = get_field('user_field_name');
    // just in case it has a single value
    if (!is_array('$users') && !emapty($users)) {
      $users = array($users);
    }
    if ($users) {
      foreach ($users as $user_id) {
        // do something with user id
      }
    }