field_get_items

7 field.module field_get_items($entity_type, $entity, $field_name, $langcode = NULL)
8 field.module field_get_items($entity_type, $entity, $field_name, $langcode = NULL)

Returns the field items in the language they currently would be displayed.

Parameters

$entity_type: The type of $entity; e.g., 'node' or 'user'.

$entity: The entity containing the data to be displayed.

$field_name: The field to be displayed.

$langcode: (optional) The language code $entity->{$field_name} has to be displayed in. Defaults to the current language.

Return value

An array of field items keyed by delta if available, FALSE otherwise.

Related topics

3 calls to field_get_items()

File

modules/field/field.module, line 956
Attach custom data fields to Drupal entities.

Code

function field_get_items($entity_type, $entity, $field_name, $langcode = NULL) {
  $langcode = field_language($entity_type, $entity, $field_name, $langcode);
  return isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : FALSE;
}

Comments

Related API Function field_view_value()

It is worth noting that field_get_items() returns raw values the use of which can be a security risk. Passing the raw values through field_view_value() handles the sanitizing of the values.

Context

field_get_items() without an explicit langcode parameter should be used only in a display/render context since it will return the field items corresponding to the current display language.

set value of field

Is there any function like "field_set_items()" ? To set value of field?

on set & get

$entity_type for taxonomy terms is "taxonomy_term"

This might be obvious, but the first time I tried this function to pull a field from a single taxonomy term, I passed "term" as $entity_type. No-go -- got a WSOD with an unhelpful error. As taxonomy_entity_info() shows, it's "taxonomy_term".

Login or register to post comments