A colleague of mine was trying to import some huge data (from Excel) into a drupal 6 project with pure PHP and MySQL. The result is supposed to be few content-types(CCK), thousands of nodes(CCK nodes I mean),some vocabularies and few other things.

Seeing him trying to decipher the tables involved, I suggested instead of trying to reverse-engineer what CCK is doing, he should use CCK API. The problem is I couldn't find any such thing as CCK API!

Despite my heavy search to no avail, I can't in any right mind believe this to be true. I say, to myself, perhaps I can't find it ?

So how do you add a content-type, a CCK node etc etc Pragmatically ? How do you utilize CCK in PHP code ? not from the user interface ?

  • 1
    If your issue primarily relates to importing content, I would strongly suggest looking into the Feeds module, which can import nodes from a number of different file types (including CSV) and map the data in that file to specific fields and other attributes of a certain node type.
    – sheena_d
    Aug 17, 2012 at 14:50
  • @sheena_d That's a good point - might be worth adding an answer to that effect, it's a good alternative
    – Clive
    Aug 17, 2012 at 16:30
  • Thanks. I think your answer is more correct in terms of answering the question as it is worded (i.e. for users who find this thread by searching), but it sounds like OP's specific situation could benefit from a different approach.
    – sheena_d
    Aug 17, 2012 at 23:24
  • @sheena_d Although the motive was the migration at first, after a while I was seriously wondering about the general question of leveraging CCK in API. Thanks for the very useful answer though. Aug 18, 2012 at 13:27

2 Answers 2


No, it's not true.

CCK does its field processing when node API hooks are invoked, so when you (or another system process) call node_save(), CCK will run through the node object and save any field values it needs to.

For example, this code would load a node, change the value of a field called field_my_field, and then save that to the database:

$node = node_load($nid);

$node->field_my_field[0] = array('value' => 'Some new value');


There are also CRUD functions in includes/content.crud.inc which will come in handy to create fields and instances on the fly.


Clive's answer is spot-on in regards to how to use CCK programatically. However, the question specifically mention content migration from spreadsheet data, and for that the Feeds module is a really useful tool.

The Feeds module provides a user interface for importing content from a few different types and sources of structured data including RSS feeds, XML and CSV files. In this situation, you would save the data in Excel as a CSV file and create a custom Feeds importer that maps the columns of the CSV to different fields and attributes of a specific node type. Be sure to read the very thorough documentation to learn the details of using this module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.