7.x field.info.inc field_info_field($field_name)

Returns data about an individual field, given a field name.

Parameters

$field_name: The name of the field to retrieve. $field_name can only refer to a non-deleted, active field. For deleted fields, use field_info_field_by_id(). To retrieve information about inactive fields, use field_read_fields().

Return value

The field array, as returned by field_read_fields(), with an additional element 'bundles', whose value is an array of all the bundles this field belongs to keyed by entity type. NULL if the field was not found.

See also

field_info_field_by_id()

Related topics

62 calls to field_info_field()
CommentFieldsTest::testCommentDefaultFields in modules/comment/comment.test
Tests that the default 'comment_body' field is correctly added.
comment_submit in modules/comment/comment.module
Prepare a comment for submission.
EntityFieldQuery::addFieldCondition in includes/entity.inc
Adds the given condition to the proper condition array.
EntityFieldQuery::fieldOrderBy in includes/entity.inc
Orders the result set by a given field column.
FieldAttachStorageTestCase::testFieldStorageDetailsAlter in modules/field/tests/field.test
Test storage details alteration.

... See full list

File

modules/field/field.info.inc, line 522
Field Info API, providing information about available fields and field types.

Code

function field_info_field($field_name) {
  $cache = _field_info_field_cache();
  return $cache->getField($field_name);
}

Comments

AaronELBorg’s picture

Helpful hint.......

It's probably been a while since you set up your content type and entered in your "$field_name", eh?

...and now you're knee-deep in your db looking for said "$field_name"??

$field_name = 'the_db_field_you_want' sans the 'field_data' bit.

So, in your db, if the field name you want is called 'field_data_yep_mcyepperson', then $field_name will be 'yep_mcyepperson'.

This was throwing me for longer than I care to admit.

In the interest of saving someone else the hassle, I post here cleansing myself of all shame.

(OK, only some of it.)

AaronELBorg’s picture

Kind of a confusing 'helpful hint' there, Aaron.

It would actually be "field_yep_mcyepperson" and not just "yep_mcyepperson".

By the way, you look great today.

-Aaron

Trey’s picture

Just to clarify, fields created through the UI automatically have "field_" prepended to them, but not all fields do. In his example "field_data_yep_mcyepperson" the field name would, indeed, be "yep_mcyepperson". If the table had the name "field_data_field_yep_mcyepperson", then you would be right and it would be "field_yep_mcyepperson"

NancyDru’s picture

Interestingly, it appears that the data returned does not include the field label.

charlietoleary’s picture

I believe this information is stored in field instances:
field_info_instance

jyraya’s picture

Let's say I have a process that store a list of names of fields that could be deleted between the list creation and its actual use. What do I receive as info if I use this function on a field that has been deleted?

Do I receive info or not? My test seems to say that I receive information but I would like a confirmation as the doc says: "$field_name can only refer to a non-deleted, active field."