I recently tried updating my code to use object wrappers to access field values. Now I have this:
$wrapper = entity_metadata_wrapper("node", $nid); print($wrapper->field_property_sample()->value());
instead of this:
print($node->field_property_sample[LANGUAGE_NONE][0]["value"]);
Sometimes I run into a problem:
EntityMetadataWrapperException: unknown data property field_property_sample.
Is there any way around this?
I have about 10 of these fields that can throw this exception, and it really gets ugly
$wrapper = entity_metadata_wrapper("node", $nid); try { print($wrapper->field_property_sample()->value()); } catch (EntityMetadataWrapperException &e){ print(""); }
Is there any function that I can more or less call it that?
$wrapper = entity_metadata_wrapper("node", $nid); print($wrapper->field_property_sample->exists() ? $wrapper->field_property_sample->value() : "" );
source share