2

Let's say I have an articles content type, and a field_tags reference field (with multiple values referencing a "tag" vocabulary)

To retrieve articles referencing, say, "tag1" or "tag2", I do this:

jsonapi/node/article?
&filter[tags][condition][path]=field_tags.id
&filter[tags][condition][operator]=IN
&filter[tags][condition][value][]=id-of-tag1
&filter[tags][condition][value][]=id-of-tag2

That gives me all articles that have either tag1 or tag2.

However, How can I get all articles that have both tag1 and tag2?

2 Answers 2

0

I have tried as follow

/jsonapi/node/article?filter[field_tags.meta.drupal_internal__target_id]=5&filter[field_tags.meta.drupal_internal__target_id]=6

enter image description here

you can see in the screen shot only 1 node filtered which has both 5 & 6 term id.

2
  • Thanks for the reply! When I try this it only returns nodes that have the last value in the filter. So, in your example I think this would only return nodes which have the term id of 6 . In your test, did you have nodes that had only the term id 6? I think they will be returned with that query.
    – Hubert
    Jan 19, 2022 at 16:29
  • Yes you are right when i added node only with term id 6 that is also filtered.
    – khurrami
    Jan 20, 2022 at 7:15
0

You can use condition grouping and have like below :

?filter[tag-group][group][conjunction]=AND

&filter[tagA-filter][condition][path]=field.tags.id
&filter[tagA-filter][condition][value]=id-of-tag1
&filter[tagA-filter][condition][memberOf]=tag-group

&filter[tagB-filter][condition][path]=field.tags.id
&filter[tagB-filter][condition][value]=id-of-tag2
&filter[tagB-filter][condition][memberOf]=tag-group

I have not tried that but I think you can even use a code like this:

?filter[tagA-filter][condition][path]=field.tags.id
&filter[tagA-filter][condition][value]=id-of-tag1
&filter[tagB-filter][condition][path]=field.tags.id
&filter[tagB-filter][condition][value]=id-of-tag2

just notice that in this case two different key is used for conditions

1
  • Unfortunately that doesn't seem to work. When I try it doesn't return any result.
    – Hubert
    Jan 20, 2022 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.