gpt4 book ai didi

php - 如何从查询中获取节点

转载 作者:可可西里 更新时间:2023-10-31 23:00:34 25 4
gpt4 key购买 nike

我想从节点类型中获取字段值并对其进行更改。
我有这个代码,我不知道如何使用它:

$query = \Drupal::entityQuery('node')
->condition('type', 'article');
$nids = $query->execute();
$nodes = $node_storage->loadMultiple($nids);

最佳答案

EntityQuery输出是一个数组,必须在foreach循环中运行。

$query = \Drupal::entityQuery('node')
->condition('type', 'article'),
->condition('field_foo', 42); // some condition
$nids = $query->execute();
$nodes = $node_storage->loadMultiple($nids);

foreach ($nodes as $n) {
echo $n->title->value;

// do whatever you would do with a node object (set fields, save, etc.)
$n->set('title', "this is a test");
$n->save();
}

关于php - 如何从查询中获取节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com