How to render custom field taxonomy on Drupal 7?

Marco Panichi picture Marco Panichi · May 27, 2012 · Viewed 8k times · Source

I've created some custom field in my taxonomy vocabulary called Categories: - fotogallery (multiple files) - incipit (plain text) - ...

But I don't know how to render them.

I've tried field_view_field but it refers just to entity. I've tried render and drupal_render also.

Actually I'm accessing directly to $term->field_incipt['und'][0]['safe_value'] property, that I konw it's not recommended.

Any ideas?

Answer

Clive picture Clive · May 27, 2012

Taxonomy terms in Drupal 7 are entities, and as such you can use field_view_field()to safely get the render array:

$view = field_view_field('taxonomy_term', $term, 'field_incipt'); 
print render($view);