I'm attempting to get the taxonomy term id from a field in the node template for a content type. I'm currently rendering the names of the terms using this


This works fine for grabbing the names of the terms. However I would like to be able to grab the actual term ids from those fields instead of just the names. Using devel I do see that that information exists, however I'm not sure how to refer to it.

2 Answers 2


Updating the Answer:You can use template_preprocess_node. in your theme template.php

function YourTheme_preprocess_node(&$variables) {
  $variables['tags_tids'] = array();
  foreach ($$variables['field_tags'] as $key => $tag) {
    $variables['tags_tids'] = $tag['tid'];

then in your node.tpl you could loop through the "$tags_tids"array, and do whatever you want.

  • Sorry I forgot to mention that I already tried that. When I do that all it spits out is 'Array'
    – Amy
    Aug 10, 2015 at 20:13
  • not so bad, try to loop through array using foreach
    – sam2de
    Aug 10, 2015 at 20:16
  • Printing out the items of the foreach loop gives me: '1', 'markup', 'Array', 'Array', 'TagName', but no term id.
    – Amy
    Aug 10, 2015 at 20:24
  • Just updated the answer with different way to get the tids. give it a shot.
    – sam2de
    Aug 10, 2015 at 21:31

Simply double click the value you called in Devel and you will be offered the concrete path to your value. It then may be displayed like $content->field_tags[LANGUAGE_NONE][0]['tid']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.