如何使用节点标记/术语填充计算字段



我正在尝试使用与节点关联的术语/标签以及正文填充计算字段。使用"$node->身体"让身体进入是可以的,但我不确定如何引入标签?

我想要的词汇的 VID 是"4" - 所以我希望文章被标记的所有 VID 4 术语以及正文都显示在此字段中。

我这样做是为了自定义搜索目的,可以同时搜索标签和正文文本,但我相信代码也会在未来的项目上派上用场。

我解决了。以下是我在计算字段的"计算代码"框中输入的完整代码:

// Specify the vocabulary you want to pull tags from for the node
$vid = 4;
// String together the term array with a pipe between each term
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
if ($terms) {foreach ($terms as $term) {$node_terms .= ' | ' . $term->name;}}
// Merge terms and body into field value
$node_field[0]['value'] = $node_terms ." <br><br>". $node->body;

希望可以帮助将来遇到类似问题的人:)

最新更新