Using a filter or an argument to restrict terms by parent doesn't allow showing terms that have no parent, ie whose parent tid is 0 in the term_hierarchy table.
My use case is that I'm trying to reimplement the list of image galleries for image_gallery module.
So I need a view of terms, that I can filter to show the children of the current term.
I've added the fields I want, added the 'Parent term' relationship, and added the 'Term ID' argument via that relationship.
Here's my query:
SELECT term_data.tid AS tid,
term_data.name AS term_data_name,
term_data.vid AS term_data_vid,
term_data.description AS term_data_description
FROM term_data term_data
LEFT JOIN term_hierarchy term_hierarchy ON term_data.tid = term_hierarchy.tid
LEFT JOIN term_data term_data_term_hierarchy ON term_hierarchy.parent = term_data_term_hierarchy.tid
WHERE term_data_term_hierarchy.tid = <tid arg goes here>
This is great for an argument tid of say, 1. But with 0, there isn't anything joined on from the term_data_term_hierarchy, so there's no term_data_term_hierarchy.tid to test.
So we get an empty result, instead of the terms that have no parent.
I think this is a common enough use case to warrant a 'Parent term' field that provides an argument and a filter.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | views_taxonomy_parent_tid_argument.patch | 703 bytes | joachim |
Comments
Comment #1
joachim commentedHere's a patch.
Comment #2
jackbravo commentedI really could use this.
+1
I've tested it also, and works as expected. Although I don't understand much the code.... =P guess I need to view more "views" code.
Comment #3
merlinofchaos commentedCommitted. Thanks!