Search code examples
drupal-7blogs

Drupal blog entry programmatically


I'm trying to make a blog entry programmatically using this code.

$node->title = $_POST['title'];
$node->created = time();
$node->changed = time();
$node->status = 1; //published
$node->comment=1;
$node->promote = 0;
$node->sticky = 0;
$node->language='en';
$node->body = $_POST['content'];
$node->type = 'blog';
node_save($node);
print_r($node);

The node gets created on the database but when I open the blog entry on the website it doesn't show the body. Is this the correct way of doing it?


Solution

  • And this didnt blow up??? Wow. That's surprising. I would try $node->body[$node->language][0]['value'] = $_POST['content']; because body is a text field now.