views:

465

answers:

4

In views, is it possible to configure a cck taxonomy field so that a user search for higher level taxonomy terms also matches its parents? Say that I have this taxonomy called Places:

Asia
    China
        Shanghai
        Beijing
    Japan
        Tokyo
        Nagoya
    Indonesia
        Bandung
        Banjar
Europe
    France
        Paris
        Lyon
    Germany
        Berlin
        Hamburg
    UK
        London
        Birmingham
North America
    Cananda
        Toronto
        Ottawa
    USA
        New York
        Texas

I want users to be able to select, say, Europe and find all content matching France, Germany or UK and their children nodes.

A: 

You could use taxonomy_get_tree() with the $parent argument of the term to get a list of terms and then use that in a WHERE x IN () clause, this is ugly and will be limited to a certain number of terms, but will do what you want.

You may find that solr will do this out of the box, but I don't know that for sure.

Jeremy French
A: 

you can use taxonomy treemenu module from here, it will cost you less than 10 minutes :) , read QUICKSTART file from there.

A: 

When you save an item with taxonomy Shanghai, the article gets the taxonomy of Shanghai only.

Ideally you would like the article to get the taxonomy of Asia, China, Shanghai. This way you will get the article when someone searches even for Asia.

The way to do this is use the Hierarchical Select Module. There is a setting in it that will force all the taxonomy of the parent items (i.e. Asia, China) to be saved also when Shanghai is saved.

Please ask me if you have trouble locating this setting.

Sid NoParrots
A: 

I believe he is referring to doing this with Views, so that when someone searches and says 'Japan', it gets results tagged with Asia too. This would require an argument, Taxonomy: Term ID (with depth).

From there, you would inspect the $node->taxonomy, and using the tid, get its parent, use taxonomy_get_tree to get the children, and return all values. That requires writing some PHP code to validate and return the taxonomy though. If you don't know how to do that I can elaborate.

Kevin