Drupal Coding D7 - Taxonomy - How do I establish the hierarchy and associated fields for taxonomy terms? Reviewing the code in Taxonomy.module I determined the array to define a taxonomy terms as:

 'taxonomy_term' =&gt; array(
      'label' =&gt; t('Taxonomy term'),
      'controller class' =&gt; 'TaxonomyTermController',
      'base table' =&gt; 'taxonomy_term_data',
      'uri callback' =&gt; 'taxonomy_term_uri',
      'fieldable' =&gt; TRUE,
      'entity keys' =&gt; array(
        'id' =&gt; 'tid',
        'bundle' =&gt; 'vocabulary_machine_name',
        'label' =&gt; 'name',
      ),
      'bundle keys' =&gt; array(
        'bundle' =&gt; 'machine_name',
      ),
      'bundles' =&gt; array(),
      'view modes' =&gt; array(
        // @todo View mode for display as a field (when attached to nodes etc).
        'full' =&gt; array(
          'label' =&gt; t('Taxonomy term page'),
          'custom settings' =&gt; FALSE,


Assigning the correct info in the array and calling taxonomy_save_term($term); creates the term, but I have not unearthed the method or array fields necessary to define the hierarchy and attach data fields.  

Are there additional array key/values to identify the parent/children and fields? 

Are the fields attached to a term in a separate operation after the term is created?

What array keys are required to create the term?
Here is an example:

// create the Foo vocabulary
$vocabulary = new stdClass();
$vocabulary-&gt;name = "Foo Name";
$vocabulary-&gt;machine_name = "foo_vocab";
$vocabulary-&gt;description = "Foo Description";
taxonomy_vocabulary_save($vocabulary);
// annoyingly taxonomy_vocabulary_save doesn't return any information about the vocabulary
$voc_vid = db_query("SELECT v.vid FROM {taxonomy_vocabulary} v WHERE v.machine_name = 'foo_vocab'")-&gt;fetchField();
$terms = array(
  'bar',
  'bat',
);
foreach ($terms as $term_name) {
  $term = new stdClass();
  $term-&gt;vid = $voc_vid;
  $term-&gt;name = $term_name;
  taxonomy_term_save($term);
}