How to create entity reference field from custom entity to specific content type I'm on Drupal 8, using BaseFieldDefinition::create('entity_reference') on my custom entity type to add entity reference field;

I also use this -&gt;setSetting('target_type', 'node') to get nodes but this gives me all nodes of any content type;

Is there any way or possibility to filter these nodes to specific content type?

Here is the code for my field:

$fields['project_id'] = BaseFieldDefinition::create('entity_reference')
      -&gt;setLabel(t('Project'))
      -&gt;setDescription(t('The project ID, transaction was created for.'))
      -&gt;setSetting('target_type', 'node')
      -&gt;setSetting('handler', 'default')
      -&gt;setTargetEntityTypeId('project')
      -&gt;setDisplayOptions('view', array(
        'label'  =&gt; 'hidden',
        'type'   =&gt; 'project',
        'weight' =&gt; 0,
      ))
      -&gt;setDisplayOptions('form', array(
        'type'     =&gt; 'entity_reference_autocomplete',
        'weight'   =&gt; 5,
        'settings' =&gt; array(
          'match_operator'    =&gt; 'CONTAINS',
          'size'              =&gt; '60',
          'autocomplete_type' =&gt; 'tags',
          'placeholder'       =&gt; '',
        ),
      ))
      -&gt;setDisplayConfigurable('form', TRUE)
      -&gt;setDisplayConfigurable('view', TRUE);


I want this field to be referenced to Content Type called project and not all types of nodes.
You're looking for the handler_settings setting, which provides configuration for the handler you've chosen, in your case, you want:

$handler_settings = [
  'target_bundles' =&gt; [
    'project' =&gt; 'project',
  ],
];


As always with fields, widgets and formatters, just create a configurable field in the UI, export it and look at the settings there. You can always copy the settings and other things almost 1:1 from the exported YAML files to a PHP array.