duanaixuan7385 2017-05-05 06:52
浏览 22


I am trying to create nodes in Drupal 7 using a php script I then execute using Drush.

While I am able to create a basic node with a title, I am not able to set the body for some reason.

I have tried two different approaches using different advice I found on other forums.

In the first case, setting node elements directly:

$node->title = 'Your node title';
$node->body[$node->language][0]['value'] = "<p>this is a test</p>";
$node->body[$node->language][0]['summary'] = "body summary;
$node->body[$node->language][0]['format'] = 'full_html';

In the second cases, using Entity Wrappers:

$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->body->set(array('value' => '<p>New content</p>', 'format' => 'full_html'));

In both cases I am saving the node like follows:

$node = node_submit($node);

And in both cases I get a new node published, but the body never gets set or displays.

How do I correctly set the body of a new node I am saving?

  • 写回答

3条回答 默认 最新


      相关推荐 更多相似问题


      • ¥30 VB6.0操作 webview2内核的浏览器如何精确实现网页弹窗处置
      • ¥15 pr导出的视频打不开,提示“缺少编解码器”怎么解决
      • ¥15 html里js获取php参数值不成功,帮改代码
      • ¥20 如何控制ant design的InputNumber组件 最多输入5位小数
      • ¥15 c语言学生基本信息管理系统
      • ¥100 火车头采集器采集求解
      • ¥88 关于#运行时间 时间重叠 和非重叠#的问题,如何解决?
      • ¥15 C语言,密切接触者追踪
      • ¥20 关于计算机网络问题,请附带讲解
      • ¥30 自动识别图像目标并判断