diff --git a/src/Plugin/views/argument/IndexNameDepth.php b/src/Plugin/views/argument/IndexNameDepth.php
index a51f97b..941904a 100644
--- a/src/Plugin/views/argument/IndexNameDepth.php
+++ b/src/Plugin/views/argument/IndexNameDepth.php
@@ -159,60 +159,25 @@ class IndexNameDepth extends ArgumentPluginBase {
   public function query($group_by = FALSE) {
     $this->ensureMyTable();
 
-    if (!empty($this->options['break_phrase'])) {
-      $break = static::breakString($this->argument);
-      if ($break->value === [-1]) {
-        return FALSE;
+    $break = static::breakString($this->argument);
+    if (count($break->value) > 1) {
+      if (!empty($this->options['break_phrase'])) {
+        if ($break->value === [-1]) {
+          return FALSE;
+        }
+        $operator = (count($break->value) > 1) ? 'IN' : '=';
+        $tids = $break->value;
       }
-
-      $operator = (count($break->value) > 1) ? 'IN' : '=';
-      $tids = $break->value;
     }
     else {
-      $operator = "=";
+      $operator = "IN";
       $tids = $this->argument;
     }
 
     // Now build the subqueries.
-    if (is_string($tids)) {
-      if ($this->moduleHandler->moduleExists('pathauto')) {
-        $query = $this->database->select('taxonomy_term_field_data', 't')
-          ->fields('t', ['tid', 'name']);
-
-        // Filter by vocabulary ID if one or more are provided.
-        if (!empty($this->options['vocabularies'])) {
-          $query->condition('t.vid', $this->options['vocabularies'], 'IN');
-        }
-
-        $results = $query->execute()->fetchAll(\PDO::FETCH_OBJ);
-
-        // Iterate results.
-        foreach ($results as $row) {
-          if ($this->pathautoAliasCleaner->cleanString($row->name) == $this->pathautoAliasCleaner->cleanString($tids)) {
-            $tids = $row->tid;
-          }
-        }
-      }
-      else {
-        // Replaces "-" with space if exist.
-        $argument = str_replace('-', ' ', $tids);
-        $query = $this->database->select('taxonomy_term_field_data', 't')
-          ->fields('t', ['tid', 'name']);
-
-        // Filter by vocabulary ID if one or more are provided.
-        if (!empty($this->options['vocabularies'])) {
-          $query->condition('t.vid', $this->options['vocabularies'], 'IN');
-        }
-
-        $query->condition('t.name', $argument, '=');
-
-        $results = $query->execute()->fetchAll(\PDO::FETCH_OBJ);
-
-        // Iterate results.
-        foreach ($results as $row) {
-          $tids = $row->tid;
-        }
-      }
+    $tids = $this->getTidsFromNames(is_string($tids) ? [$tids] : $tids);
+    if (empty($tids)) {
+      return FALSE;
     }
 
     // Now build the subqueries.
@@ -240,7 +205,49 @@ class IndexNameDepth extends ArgumentPluginBase {
     }
 
     $subquery->condition($where);
-    $this->query->addWhere(0, "$this->tableAlias.$this->realField", $subquery, 'IN');
+    $ids = array_keys($subquery->execute()->fetchAllKeyed());
+    if (empty($ids)) {
+      return $this->query->addWhere(0, "$this->tableAlias.$this->realField", [-1], 'IN');
+    }
+    return $this->query->addWhere(0, "$this->tableAlias.$this->realField", $ids, 'IN');
+    }
+
+    /**
+    * Get the taxonomy term ids from the names.
+    *
+    * @param array $names
+    *   Array of taxonomy names.
+    *
+    * @return array
+    *   Array of entity ids.
+    */
+   protected function getTidsFromNames(array $names) {
+  
+      $query = $this->termStorage->getQuery();
+      // Filter by vocabulary ID if one or more are provided.
+      if (!empty($this->options['vocabularies'])) {
+        $query->condition('vid', $this->options['vocabularies'], 'IN');
+      }
+  
+      $alias_cleaner = NULL;
+      if (\Drupal::service('module_handler')->moduleExists('pathauto')) {
+        // Service container for alias cleaner.
+        $alias_cleaner = \Drupal::service('pathauto.alias_cleaner');
+      }
+  
+      $tids = [];
+      foreach ($this->termStorage->loadMultiple($query->execute()) as $term) {
+        foreach ($names as $name) {
+          if (
+            ($alias_cleaner && $alias_cleaner->cleanString($term->label()) == $alias_cleaner->cleanString($name)) ||
+            (!$alias_cleaner && $term->label() == str_replace('-', ' ', $name))
+          ) {
+            $tids[] = $term->id();
+            break;
+          }
+        }
+      }
+      return $tids;
   }
 
   /**
