gpt4 book ai didi

arrays - Drupal - 获取自定义分类字段

转载 作者:行者123 更新时间:2023-12-02 03:30:48 25 4
gpt4 key购买 nike

我正在尝试将自定义字段分配给分类法。我已经尝试过:

$vid = 'zeme';
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);

$terms 现在存储名为“zeme”的词汇表中的所有术语。问题是当我打印这个变量时,它没有显示我需要获取的自定义字段。知道如何获得这个自定义字段吗?我的代码如下所示:

 $vid = 'zeme';
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
foreach ($terms as $term) {
$term_data[] = array(
'id' => $term->tid,
'name' => $term->name
);
}

最佳答案

这里是loadTree函数官方文档: TermStorage::loadTree

当您使用loadTree函数时,它只会获取最少的数据以节省执行时间。您可以看到有一个 $load_entities 参数默认设置为 false

bool $load_entities: If TRUE, a full entity load will occur on the term objects. Otherwise they are partial objects queried directly from the {taxonomy_term_data} table to save execution time and memory consumption when listing large numbers of terms. Defaults to FALSE.

因此,如果您想获取每个分类术语的所有数据,则必须将 $load_entities 设置为 true

$vid = 'zeme';
$terms =\Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadTree($vid, 0, null, true);

关于arrays - Drupal - 获取自定义分类字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51926632/

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