I agree we should have a more general filter operator in the core to get tree.
I’m creating a flow chart plugin that can show the tree, and I will allow user to use custom field, not limited to tags
field. So I have to copy&paste and do modification to your code, instead of reuse it and just pass-in parameters.