1

I am using Drupal 7. I have a content type "Public Resource" that uses a hierarchical vocabulary called "Resource Topics" that has up to 3 levels (parent->child->child of child).

We have about 1000 Public Resources that are created. It has come to my attention that when our staff has been creating Public Resources nodes and choosing the "Resource Topics" terms if they choose a child they don't always choose the parent of that child.
This creates data inconsistency and I am trying to find out a way of identifying what "Public Resources" fit into this category.

I don't know if there is a way of setting up a view in order to do this but I wasn't able to figure this out.

I am also trying to write a database query that would identify these "Public Resource" nodes but since I can't pass in a field value to a subquery. This query returns all topics that are associated with a public resource and has parent data and parent term is associated with the public resource node.

SELECT node.nid, taxonomy_term_data.tid, taxh1.parent
  FROM node 
  LEFT JOIN taxonomy_index ON taxonomy_index.nid=node.nid 
  LEFT JOIN taxonomy_term_data ON taxonomy_term_data.tid = taxonomy_index.tid 
  LEFT JOIN taxonomy_vocabulary ON taxonomy_vocabulary.vid = taxonomy_term_data.vid 
  LEFT JOIN taxonomy_term_hierarchy AS taxth1 ON taxth1.tid = taxonomy_term_data.tid 
  WHERE node.type = "public_resource" 
    AND taxonomy_vocabulary.name= "Resource Topic"
    AND taxth1.parent NOT IN (
      SELECT taxonomy_term_data.tid
        FROM node 
        LEFT JOIN taxonomy_index ON taxonomy_index.nid=node.nid 
        LEFT JOIN taxonomy_term_data ON taxonomy_term_data.tid = taxonomy_index.tid 
        LEFT JOIN taxonomy_vocabulary ON taxonomy_vocabulary.vid = taxonomy_term_data.vid 
        LEFT JOIN taxonomy_term_hierarchy ON taxonomy_term_hierarchy.tid = taxonomy_term_data.tid 
        WHERE node.type = "public_resource" AND taxonomy_vocabulary.name = "Resource Topic" AND taxonomy_index.tid = taxth1.parent
    )
2
  • 1
    I don't understand what this means: "if they choose a child they don't always choose the parent of that child". Can you please edit the original post and elaborate on that? Please also include more information on how you have created this hierarchy.
    – Jaypan
    Commented Jan 13, 2023 at 2:12
  • This does not answer the OP, but if your issue is having your users not selecting the parent term, maybe you should give a look at drupal.stackexchange.com/a/42357/89900
    – misterdidi
    Commented Jan 16, 2023 at 8:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.