I want to load term fields in my application. Can I use entity metadata wrapper with reference to terms?


Yes. Like so:

$term_w = entity_metadata_wrapper('taxonomy_term', taxonomy_term_load(TERM_ID));

The first parameter is the entity type ID. If you visit MODULE_NAME_entity_info(), you can see the key of the definition will match the ID you need to load it.

  • If i used $term_w = entity_metadata_wrapper('taxonomy_term', taxonomy_term_load(TERM_ID)); its giving me error saying that property its not define. e.g $term_w->field_test->value() – Harshil Sep 13 '13 at 6:16
  • That worked for me, though. Try $term_w->getPropertyInfo() to see what properties are defined. – greg_1_anderson Nov 24 '13 at 3:39

Sam152 is right, but you don't actually need to convert the term_id to an object, it will work with just the term_id being passed as is:

$term_w = entity_metadata_wrapper('taxonomy_term', TERM_ID); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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