I'm trying to create a node using PHP. The below code works fine until I use any language code other than 'LANGUAGE_NONE'.

$node = new stdClass();
$node->type = 'recipe';
$node->uid = 1;
$node->language = LANGUAGE_NONE;
$node->title = $item['title'];
$node->body[$node->language][0]['value']= $item['description'];
$node->body[$node->language][0]['format']= 'plain_text';      

If I use "en" instead of "LANGUAGE_NONE" then the node is created without any field being populated. That is, there is only a title; the body is blank.

Locale module is enabled and i18n is installed and enabled.

What should I do?


1 Answer 1


You also need to set the language of the fields.

$node->language = 'en';
$field_langcode = field_language('node', $node, 'body');
$node->body[$field_langcode][0]['value']   = $body_text;
$node->body[$field_langcode][0]['summary'] = text_summary($body_text);
$node->body[$field_langcode][0]['format']  = filter_default_format();

See this comment (https://drupal.org/comment/5464106#comment-5464106) for more info.


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.