I am getting my term description using taxonomy_get_term_by_name().

I'm having problems with term names like "barnes & noble" and "Café"; I guess it must have something to do with the special characters. How can I filter my taxonomy name input the best way to get back term results?

I'm using the function in a views-view-list.tpl.php template, where $title is outputting the taxonomy; then I use $title with the following code.

$terms = taxonomy_get_term_by_name($title, 'places');

$title seems to be stripped from all kind of htmltags - its plain text.

  • What are the errors you are getting ? I just tested the same in d7 instance and i don't see any with above terms ?
    – Anil Sagar
    Oct 19, 2012 at 15:26
  • Hi Anil, I'm not getting any errors, just an empty array as no taxonomy by that name exist. Oct 19, 2012 at 15:31
  • I just created two terms under tags vocab and called $term = taxonomy_get_term_by_name("barnes & noble"); drupal_set_message("<pre>" . print_r($term, 1) . "</pre>"); It worked perfectly !!
    – Anil Sagar
    Oct 19, 2012 at 15:33
  • Hi Anil, You are right. I guess the problem must be elsewhere then. Oct 19, 2012 at 15:45
  • How are you printing details ? Can you post your code ?
    – Anil Sagar
    Oct 19, 2012 at 15:52

1 Answer 1


It was only the & charter there was making problems. This was the solution:

$terms = taxonomy_get_term_by_name(str_replace('&amp;', '&', $title), 'places');

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.