Add taxonomy field to a bundle programmatically I'm currently developing a module which provides a content type called "Structural machinery" . This type should also provide a taxonomy term based on different manufacturers providing the machine (eg CAT or Komatsu) , I know how to create a taxonomy vocabulary programmatically but the question is how to attach a taxonomy field to my bundle.

this is the code used to implement the taxonomy term :

$term = new stdClass();
$term -&gt; name = $t('Manufacture');
$term -&gt; machine_name = 'manufacture';
$term -&gt; description = $t('Description');
$term -&gt; hierarchy = 2;
$term -&gt; module = 'construction_machinery';
$term -&gt; weight = 1;
taxonomy_vocabulary_save($term);
First create your field

$field_name = 'field_manufacture';

$field = field_info_field($field_name);
if(!$field){
  $field = array(
    'settings' =&gt; array(
      'allowed_values' =&gt; array(
        0 =&gt; array(
          'vocabulary' =&gt; 'manufacture',
          'parent' =&gt; '0',
        ),
      ),
    ),
    'field_name' =&gt; $field_name,
    'type' =&gt; 'taxonomy_term_reference',
    'module' =&gt; 'taxonomy',
    'active' =&gt; '1',
    'cardinality' =&gt; '1',
  );
  field_create_field($field);
}


Then create your instance(s)

$node_types = array('page','whatever');
foreach($node_types as $type){

  $instance = field_info_instance('node',$field_name,$type);
  if(!$instance){
    $instance = array(
      'label' =&gt; 'Manufacture',
      'widget' =&gt; 
      array(
        'weight' =&gt; 3,
        'type' =&gt; 'options_select',
        'module' =&gt; 'options',
        'active' =&gt; 1,
      ),
      'field_name' =&gt; $field_name,
      'entity_type' =&gt; 'node',
      'bundle' =&gt; $type,
    );

    field_create_instance($instance);
  }

}


if you do var_export the return from field_info_field and field_info_instance of an existing field, you can see how the field arrays are structured &amp; use this structure when creating new ones.