How to list CCK fields by content type in Drupal
Asked Answered
M

3

7

To get a list of a content type's cck fields, I was hoping to use:

drupal_get_schema('content_type_mycontenttype');

but that leaves out fields with multiple values. Is there a simple call to use to get such a list?

Malaria answered 7/6, 2010 at 18:35 Comment(0)
B
3

Take a look at the content_fields function, and if doesn't that have the information you need, there is _content_type_info.

Additionally, once you have the field information, you can extract the table storage and column names using content_database_info.

Brigadier answered 7/6, 2010 at 18:48 Comment(0)
W
3

For Drupal 7, check out the field_info_instances function to retrieve a list of fields for a particular node content type.

Here is an example usage that will retrieve all the fields for a node content type.

$my_content_type_fields = field_info_instances("node", "my_node_content_type");

Wei answered 12/10, 2012 at 13:54 Comment(0)
P
1

I've used something like this before to do a quick list of CCK Field information for a content type:

    $mytype = 'article';
    $contentinfo = _content_type_info();
    $output .= "<ul>";
    foreach($contentinfo['fields'] as $field) {
        if ($field['type_name'] == $mytype) {
            $output .= '<li id="field-' . $field['field_name'] . '">' . $field['widget']['label'] . '<br>';

            if ($field['widget']['description']) {
                $output .= $field['widget']['description'] . '<br>';
            }    

            $output .= '<ul>
                    <li>Content Types: ' . $field['type_name'] . '</li>
                    <li>Type: ' . $field['type'] . '</li>
                    <li>' . $field['field_name'] . '</li>
                </ul>';
        }
    }
    $output .= '</ul>';
Placable answered 21/10, 2011 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.