Find target bundle(s) for a specific entityreference field
Drupal 8 version:

$bundles = \Drupal::entityManager()
-&gt;getAllBundleInfo()['node'];
 foreach ($bundles as $id =&gt; $value) {
 $node_fields = \Drupal::entityManager()
  -&gt;getFieldDefinitions('node', $id);
   foreach ($node_fields as $field) {
      if ($field instanceof \Drupal\field\Entity\FieldConfig) {
        if ($field-&gt;getType() == 'entity_reference') {
          $target_bundle = $field-&gt;getSettings()['handler_settings']['target_bundles'];
          kint($target_bundle);
        }
      }
    }
  }


With $target_bundle, You can do something like this as well to filter out a specific bundle:

if ($target_bundle != null &amp;&amp; key($target_bundle) == 'mybundle'){
  kint($field-&gt;id());
}