Assign existing field to new content type programmatically I'm developing a module that create a several new content types:

function create_new_content_type($type, $name){
    $t = get_t();

    $new_node = array(
        'type' =&gt; $type,
        'name' =&gt; $name,
        'base' =&gt; 'node_content',
        'custom' =&gt; TRUE,
        //'description' =&gt; 'This is an example node type with a few fields.',
    );
    $content_type = node_type_set_defaults($new_node);
    node_add_body_field($content_type);

    // Check if we create content type or update.
    $status = node_type_save($content_type);

    // Replacement rule for the messages.
    $t_args = array('%name' =&gt; $content_type-&gt;name);

    if ($status == SAVED_NEW) { // create case
        watchdog('node', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l($t('view'), 'admin/structure/types'));
        return true;
    }

    return false;
}


after that creates a new fields for that type (for example):

function createTextField($name, $label, $bundle, $required=FALSE){
    // Create the field base.
    $field = array(
        'field_name' =&gt; $name,
        'type' =&gt; 'text',
    );
    field_create_field($field);

    // Create the field instance on the bundle.
    $instance = array(
        'field_name' =&gt; $name,
        'entity_type' =&gt; 'node',
        'label' =&gt; $label,
        'bundle' =&gt; $bundle,
        // If you don't set the "required" property then the field wont be required by default.
        'required' =&gt; $required,
        'widget' =&gt; array(
            'type' =&gt; 'textfield',
        ),
    );
    field_create_instance($instance);

}


Lets assume I have already existed field with name field_my_custom how can I attach it to my new created content type? (if I understand right in the method above I only create new fields).
No creating a new instance means you are attaching that field to a content type. Here $bundle is the machine name of the content type