drupal 7 启用 签名设置 filtered html,php – 如何在Drupal 7中为节点设置自定义字段值?...
我正在嘗試使用下一代碼從外部腳本添加新節點:
define('DRUPAL_ROOT', getcwd());
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$node = new stdClass();
$node->title = "Your node title";
$node->body = "The body text of your node.";
$node->type = 'rasskazi';
$node->created = time();
$node->changed = $node->created;
$node->status = 1; // Published?
$node->promote = 0; // Display on front page?
$node->sticky = 0; // Display top of page?
$node->format = 1; // Filtered HTML?
$node->uid = 1; // Content owner uid (author)?
$node->language = 'en';
node_submit($node);
node_save($node);
但是如何設置自定義字段值(例如’sup_id’整數)?
解決方法:
像這樣:
$node->field_sup_id[LANGUAGE_NONE] = array(
0 => array('value' => $the_id)
);
如果您的字段具有多個基數,則可以添加以下額外項:
$node->field_sup_id[LANGUAGE_NONE] = array(
0 => array('value' => $the_id),
1 => array('value' => $other_id)
);
您可以使用數組的語言元素來定義此特定字段值所屬的語言:
$lang = $node->language; // Or 'en', 'fr', etc.
$node->field_sup_id[$lang] = array(
0 => array('value' => $the_id),
1 => array('value' => $other_id)
);
在調用node_save()之前添加這些,并在調用時添加/更新字段內容.
標簽:php,drupal,drupal-7
來源: https://codeday.me/bug/20190613/1235122.html
總結
以上是生活随笔為你收集整理的drupal 7 启用 签名设置 filtered html,php – 如何在Drupal 7中为节点设置自定义字段值?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 防镜像网,wordpress防止
- 下一篇: 硬盘安装opensuse linux 1