drupaldrupal-fieldsdrupal-content-typesdrupal-nodes

Drupal 7 Does "New Node Creation" initiate/prepare the Fields for different Content Types?


In Drupal 7, i need to Programmatically create the Nodes. As usual, there are Different Fields set for Different Content Types.

For very simple example:

Content Type: "car"
Fields: "Model", "Engine", "GearType"

Content Type: "article"
Fields: "Title", "Author", "Media"

What i want to be confirmed here is, while i am creating a new node, for e.g by using:

$node = new stdClass();
$node->type = "car";

Then..


Solution

  • I think this is what your looking for:

    $node = new stdClass();
    $node->type = 'article';
    node_object_prepare($node);
    

    There is a nice blog post about this here: http://www.group42.ca/creating_and_updating_nodes_programmatically_in_drupal_7