I have the term name; how on earth do I get the term ID in a block using PHP?

Simple question; hopefully it's a simple answer ;)

Comments

WorldFallz’s picture

how about _taxonomy_get_tid_from_term-- is that simple? ;-)

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

marcp’s picture

<?php
  // Get a term object by name
  $term = taxonomy_get_term_by_name($name);

  // Print the term id
  print $term->tid;
?>

Marc
-------
http://www.funnymonkey.com
Click. Connect. Learn.

aaronp’s picture

Awesome; this works with one modification. It looks like taxonomy_get_term_by_name($name) returns an array, which makes sense because the term names are not unique, only the ID's. That is, you might have a term with the same name in two separate vocabularies (or even in the same vocabulary, I suppose?).

This will print the term ID of the first matching term. A better way to do this, of course, would be to loop through all the available options and output 'em.

<?php
  // Get a term object by name
  $term = taxonomy_get_term_by_name($name);

  // Print the term id
  print $term[0]->tid;
?>

Thanks again for everyone's help.