3

In drupal 8.5 I have a taxonomy term list like this:

Term A (12 items)
  Term 1 (3 items)
  Term 2 (8 items)
  Term 3 (1 items)
Term B (3 items)
  Term 4 (1 items)
  Term 5 (2 items)

I want to use the json api to fetch all data within term B. So I expect a result set of 3 items. But when I do:

https://www.some-api.com/jsonapi/node/test?
  _format=api_json&
  filter[taxFilter][condition][path]=field_regio&
  filter[taxFilter][condition][operator]=IN&
  filter[taxFilter][condition][value][]=2 (=> id of term B)

I get a response with "data": [], This is probably because the term id of these nodes are set to the children (term 4 and 5).

But isn't drupal supposed to return all nodes in the children of term B?

Otherwise how can I get all nodes in Term A or B?

  • You can just tag those nodes with the Parent term too right? – Beebee Jun 28 '18 at 13:39
  • What is the point of the tree structure in taxonomy then? Some terms can have multiple parents, very hard for editors to know what all the parents are. – yeager Jun 28 '18 at 13:42
  • You don't have to force authors to do that, you can do it in a hook_form_submit programmatically too. But I think best way to go might be using Views, create a RESTful view that can work with hierarchical taxonomies, effectively replacing jsonapi for this call. But isn't drupal supposed to return all nodes in the children of term B? No, IIRC I don't think it works that way out of the box. – Beebee Jun 28 '18 at 13:48

Your Answer

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

Browse other questions tagged or ask your own question.