Query and load entity by Entity Type Manager
You can do this in one step by using loadByProperties():

$term = current(\Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term')
  -&gt;loadByProperties(['field_code' =&gt; $code, 'vid' =&gt; 'computer'])
);


This method is a shortcut for basic entity queries like you have here and also includes the step for loading the entities.