Populate a hierarchical select field programmatically I have to create a user, and one of the fields (Profession) is a hierarchical select based on a two level taxonomy, where the first level is "profession", and each profession has different specialities.

I can create a user and save the profession field, but the speciality is not saved, and that's what I want to do. Here is how I save the profession : 

$fields = array(
    'name' =&gt; $name,
    'mail' =&gt; $email,
    'pass' =&gt; $password,
    ...
    'field_profession' =&gt; array('und' =&gt; array(array('tid' =&gt; $tid_profession))),
);
user_save('', $fields);


Here, $tid_profession is the id of the profession term. However, when I use the id of the speciality term, the field is not saved. 

Any idea how to make this work ? Any help would be greatly appreciated.
I have saved user with custom hirerarical select field named "field_register_state" like below: it's working very well.

$account = new stdClass;
$account-&gt;is_new = TRUE;
$account-&gt;name = $username;
$account-&gt;pass = user_hash_password($form_state['values']['pass']);
$account-&gt;mail = $form_state['values']['mail'];
$account-&gt;init = $form_state['values']['mail'];
$account-&gt;status = TRUE;

$account-&gt;field_user_code = array(LANGUAGE_NONE =&gt; array(array('value'=&gt;$userCode)));
$account-&gt;field_full_name = array(LANGUAGE_NONE =&gt; array(array('value'=&gt;$form_state['values']['field_full_name']['und'][0]['value'])));
$account-&gt;roles = array(DRUPAL_AUTHENTICATED_RID =&gt; 'authenticated user',$form_state['values']['roles']=&gt;getRoleNameById($form_state['values']['roles'],$form));

$account-&gt;field_user_area_name = array(LANGUAGE_NONE =&gt; array(array('value'=&gt;$areaName)));
$account-&gt;field_created_by = array(LANGUAGE_NONE =&gt; array(array('value'=&gt;0)));
$account-&gt;field_register_state = array(LANGUAGE_NONE =&gt; array(array('tid'=&gt;$statecode)));
$account-&gt;timezone = variable_get('date_default_timezone'); 
user_save($account);
drupal_set_message(t('User Created Successfully'), 'status');


Hope this help's you..