1

How do I determine the individual field type using an EntityFieldQuery?

Here is the sample code for extracting the fields of a content type named 'digital_iq_test_2012', which contains many fields. How do I determine the type of each field?

$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'digital_iq_test_2012')
  ->propertyCondition('status', 1);
$result = $query->execute();

Any help?

  • To those people editing this question to make the uppercase 'I's into lower case 'i's...please stop it, this is an English speaking website and in English the 'I' must be capitalised :) – Clive Nov 26 '12 at 11:21
1

EntityFieldQuery essentially just prepares an SQL query and gives you the results, it doesn't return any meta information about the fields themselves.

To get that you can use the Field Info API, e.g.

// Get all fields attached to your bundle.
$fields = field_info_instances('node', 'digital_iq_test_2012');

// Loop through
foreach ($fields as $field_name => $instance) {
  // Load up field info for this field.
  $field_info = field_info_field($field_name);

  // Get the type
  $type = $field_info['type'];
}

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.