The function _content_type_info() returns all information of all fields including of shared fields correctly (one array of one field for each content type). Instead content_field() only returns the data of the last content type.

Is there another function CCK provides which enables the developer to retrieve all content types/widgets of a specified field (in my case I need all labels that field has)? Currently I use _content_type_info() and filter the result for the fieldname.

Comments

yched’s picture

Status: Active » Fixed

content_field($field_name, $type_name); provides the information for the field instance in a given type.
It fetches from the cached data built by _content_type_info() (no db hit).

content_field_instance_read(array('field_name' => $field_name)); will provide an array of all the field instances for a given field.
Each call queries the content_node_field and content_node_field_instance tables - not cached.
function is defined in cck/includes/content.crud.inc, you'll have to manually include the file before calling the function.

Roi Danton’s picture

Title: Shared field: content_field() only returns the field data of last assigned content type » Shared field: content_fields() only returns the field data of last assigned content type

Thanks for the quick answer!
Though content_field_instance_read works fine I stick to _content_type_info() due cached data is enough for me. If someone else wants to do this, too:

function content_retrieve_fieldlabels($fieldname) {
    $content_type_info = _content_type_info();        
    foreach ($content_type_info['content types'] as $content_type) {
        if (isset($content_type['fields'][$fieldname])) {
            $labels[$content_type['name']] .= $content_type['fields'][$fieldname]['widget']['label'];
        }
    }
    return $labels;
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.