Adding CCK Fields Through Modules

Original Credit to Drewish from, and of course the CCK team for such a fantastic tool. I'm just adding it here for reference, and expanding a bit with the uninstall knowledge.


  1. // Need to load the CCK include file where content_field_instance_create() is defined.
  2. module_load_include('inc', 'content', 'includes/content.crud');
  4. // If you wanted to add the field to several node types, loop over them...
  5. foreach (array('athlete', 'feature', 'product', 'tech') as $type) {
  6.   // ...and assign the node type.
  7.   $field['type_name'] = $type;
  8.   content_field_instance_create($field);
  9. }


  1.   content_field_instance_delete($field_name, $content_type);

Note that removing the last instance of a field will remove the field's definition from the database. So you're clean just doing this.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.