How to create multi-value, multi-bundle entity reference fields in code? I'm looking for example code that demonstrates creating a new entity reference field with multiple values, referring to multiple different bundles.
Sorry for the long code dump but there's really no other way to do this:

field_create_field(array(
  'translatable' =&gt; '0',
  'entity_types' =&gt; array(),
  'settings' =&gt; array(
    'target_type' =&gt; 'node',
    'handler' =&gt; 'base',
    'handler_submit' =&gt; 'Change handler',
    'handler_settings' =&gt; array(
      'target_bundles' =&gt; array(
        'article' =&gt; 'article',
        'page' =&gt; 'page',
        'webform' =&gt; 'webform',
      ),
      'sort' =&gt; array(
        'type' =&gt; 'none',
        'property' =&gt; 'nid',
        'field' =&gt; 'body:value',
        'direction' =&gt; 'ASC',
      ),
      'behaviors' =&gt; array(
        'views-select-list' =&gt; array(
          'status' =&gt; 0,
        ),
      ),
    ),
  ),
  'storage' =&gt; array(
    'type' =&gt; 'field_sql_storage',
    'settings' =&gt; array(),
    'module' =&gt; 'field_sql_storage',
    'active' =&gt; '1',
    'details' =&gt; array(
      'sql' =&gt; array(
        'FIELD_LOAD_CURRENT' =&gt; array(
          'field_data_field_entity_reference' =&gt; array(
            'target_id' =&gt; 'field_entity_reference_target_id',
          ),
        ),
        'FIELD_LOAD_REVISION' =&gt; array(
          'field_revision_field_entity_reference' =&gt; array(
            'target_id' =&gt; 'field_entity_reference_target_id',
          ),
        ),
      ),
    ),
  ),
  'foreign keys' =&gt; array(),
  'indexes' =&gt; array(
    'target_id' =&gt; array(
      'target_id',
    ),
  ),
  'field_name' =&gt; 'field_entity_reference',
  'type' =&gt; 'entityreference',
  'module' =&gt; 'entityreference',
  'active' =&gt; '1',
  'locked' =&gt; '0',
  'cardinality' =&gt; '-1',
  'deleted' =&gt; '0',
  'columns' =&gt; array(
    'target_id' =&gt; array(
      'description' =&gt; 'The id of the target entity.',
      'type' =&gt; 'int',
      'unsigned' =&gt; TRUE,
      'not null' =&gt; TRUE,
    ),
  ),
  'bundles' =&gt; array(
    'node' =&gt; array(
      'page',
    ),
  ),
));


The target_bundles in the handler_settings is where you assign the different bundles, and the cardinality of -1 ensures unlimited values for the field.

In case you're interested, this is the code that allowed me to build the above definition from an existing entity reference field (which seems to have originated at this blog post):

$entity_type = 'node';
$field_name = 'field_entity_reference';
$bundle_name = 'article';

$info_config = field_info_field($field_name);
$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
unset($info_config['id']);
unset($info_instance['id'], $info_instance['field_id']);
include_once DRUPAL_ROOT . '/includes/utility.inc';
$output = "field_create_field(" . drupal_var_export($info_config) . ");\n";
$output .= "field_create_instance(" . drupal_var_export($info_instance) . ");";
drupal_set_message("&lt;textarea rows=30 style=\"width: 100%;\"&gt;". $output .'&lt;/textarea&gt;');


It's a handy little script; I'm sure I've posted it somewhere here before but I can't find it at the moment.