Score:1

How can I find all the nodes that use a hierarchical vocabulary taxonomy term and reference a child term but not its parent term

ps flag

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
    )
Jaypan avatar
de flag
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.
misterdidi avatar
de flag
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 https://drupal.stackexchange.com/a/42357/89900
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.