drupaldrupal-6forumdrupal-forms

How to create a forum topic programmatically?


I just gone through how to create forums and containers programmatically with the below link

http://www.unibia.com/unibianet/drupal/how-create-drupal-forums-and-containers-programmatically

But never see any post(google) which create forum topic pro-grammatically, whether i should go with node_save() or any alternative.

please help me guys,

Thanks, Edvin


Solution

  • A quick, safe and easy way to create new nodes programmatically is to use node_save():

    <?php
      // Construct the new node object.
      $node = new stdClass();
    
      // Set the values for the node
      $node->title = "My new forum topic";
      $node->body = "The body of my forum topic.\n\nAdditional Information";
      $node->type = 'forum';   // Your specified content type
      $node->created = time();
      $node->changed = $node->created;
      $node->status = 1;       // To have published, else use 0
      $node->promote = 1;      // If you want promoted to front page, else use 0
      $node->sticky = 0;
      $node->format = 1;       // Filtered HTML
      $node->uid = 1;          // UID of content owner
      $node->language = 'en';
    
      // If known, the taxonomy TID values can be added as an array.
      $node->taxonomy = array(2,3,1,);
    
      node_save($node);
    ?>