简体   繁体   English

如何仅用一个术语标记 output 个节点?

[英]How to output nodes tagged with only one term?

I have many nodes with taxonomy term field "Tags"我有很多带有分类术语字段“标签”的节点

For example:例如:

1 node with tid: 10, 12, 20 1 个节点的 tid:10、12、20

2 node with tid: 10 2 节点 tid:10

3 node with tid: 10, 16, 18带有 tid 的 3 个节点:10、16、18

4 node with tid: 10, 20 4 个节点的 tid:10、20

5 node with tid: 10 5 个节点 tid:10

I try use filter Term ID = 10 in Views, but it output all nodes with term 10.我尝试在 Views 中使用过滤器 Term ID = 10,但它 output 所有节点都带有 term 10。

How I can output nodes tagged only one term - tid 10 (nodes: 2 and 5)?我如何才能将 output 个节点标记为只有一个术语 - tid 10(节点:2 和 5)?

You can check the second occurrence to verify that it exists.您可以检查第二次出现以验证它是否存在。 Here an example:这里有一个例子:

$query = $this->entityTypeManager
  ->getStorage('node')
  ->getQuery()
  ->condition('type', 'your_node')
  ->condition('tag.0.value', 10)
  ->notExists('tag.1.value');

There you are sure to have the nodes with the tag 10 and only 10.那里肯定有标签为 10 且只有 10 的节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM