From 9df8f690ac7f35df5a359c5743a1fcfecc3f67d5 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Thu, 3 Nov 2011 00:58:55 -0500
Subject: [PATCH] Issue #143817 by webchick, marvil07: Added API: Get just
 term ID by name.

---
 core/modules/taxonomy/taxonomy.module |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index eb20c26..3d535c8 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -1072,6 +1072,28 @@ function taxonomy_get_term_by_name($name) {
 }
 
 /**
+ * Returns the term ID for the given term name.
+ *
+ * NOTE: If more than one match is found, this function will return the first
+ * one it finds. If you have duplicate term names in your database, you may
+ * wish to use the more robust taxonomy_get_term_by_name() instead.
+ *
+ * @param $name
+ *   Name of the term to search for.
+ *
+ * @return
+ *   The term ID of the given term, or FALSE if none was found.
+ */
+function taxonomy_get_tid_by_name($name) {
+  return db_select('taxonomy_term_data', 't')
+    ->fields('t', array('tid'))
+    ->condition('name', db_like(trim($name)), 'LIKE')
+    ->addTag('term_access')
+    ->execute()
+    ->fetchField();
+}
+
+/**
  * Controller class for taxonomy terms.
  *
  * This extends the DrupalDefaultEntityController class. Only alteration is
-- 
1.7.7

