How to get taxonomy term name from tid?

Solutions

In Drupal 8, you can get the name of taxonomy terms this way:

$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);

$name = $term->label();

Or to load multiple:

$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple($tids);

foreach($terms as $term) {
  $name = $term->label();
}

If you're using Drupal 7 you can use taxonomy_term_load()

$term = taxonomy_term_load($tid);
$name = $term->name;

If you've got a bunch of term IDs you can save having to run a single query for each load by using taxonomy_term_load_multiple():

$tids = array(1, 2, 3);
$terms = taxonomy_term_load_multiple($tids);

foreach ($terms as $term) {
  $name = $term->name;
}

If you're stuck using Drupal 6 you can use taxonomy_get_term():

$term = taxonomy_get_term($tid);
$name = $term->name;

There's no multiple-load option for Drupal 6 that I know of unfortunately.

The following function returns the name of a taxonomy term based on its tid:

function get_term($tid) {
  return db_select('taxonomy_term_data', 't')
  ->fields('t', array('name'))
  ->condition('tid', $tid)
  ->execute()
  ->fetchField();
}

Similar questions

Show Taxonomy Name not TID in Views Query String
I'm using Views exposed filters (dropdown) based on Term Reference (taxonomy Fields.) It works but the query string it generates uses the Term ID (TID) instead of using the more readable and clean term name. How do I change the query string to use the term name instead of TID? For example: Current: http://test.com/test?gender=1 Desired: http://test...
Create Alias URL to taxonomy term page with TID
I am trying to figure out how to create a url-alias friendly url to a taxonomy term page with only the tid of the term. I know drupal does this automatically in the node, but I am trying to do this in a block. e.g. Where the term is "Texas" with tid 34, and the alias is to the taxonomy page is "/location/texas" So, instead of creating a url to this...
Prevent anonymous users from accessing "node/" node/%nid and taxonomy/term/%tid
So far, I have been reading some similar questions but I haven't found an elegant and simple way of doing this (if there is any). As I say in the question title, I don't want anonymous users to access the complete list of nodes (in node/) nor a particular node (under node/%nid), nor even a particular taxonomy term. :) My approach to this is as foll...
In Drupal 7 how to expose TID (term id) as a selectable field on the manage display section of the taxonomy page?
How can I expose the TID of a the term as a field via the manage display section of the taxonomy page?
What is taxonomy/term/tid/*
I'm first time seeing a link indexed by Google : taxonomy/term/10007/* as in here. What could be causing it? I've already GlobalRedirect enabled, also not using the View "Taxonomy term" which emulates Drupal core's handling of taxonomy/term.
Exposed filter autocomplete has TID with taxonomy term
I created a view from taxonomy terms of different country names. I added an exposed filter to allow the user to enter the country, but when the user selects the country, it automatically adds the taxonomy ID after the name. I've tried various things, from hooks to jQuery, I can't seem to figure out how to remove the TID. Please advise.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.