views:

894

answers:

2

I am trying to get a list of distinct taxonomy terms in drupal using views2. It seems it shouldnt be that big of a problem, however when i select the taxonomy:all terms, and select what vocabulary to limit to i get duplicates. The "distinct" option in drupal does nothing, and i cant find anything else that groups it together. If anyone knows anything that would be great.

Thank you.

/Anders

A: 

In case of taxonomy terms, views2 applies the distinct clause to the term id, which is rather useless in your case. So afaik there is no way to do what you want in views2 without manipulating the view via custom coding.

So you might want to take a look into hook_views_query_alter() for an option to manipulate the query used by the view. Alternatively, you could execute the view via code and filter the resultset found in $view->result after execution of the view.

But depending on what you need the list for, those methods might be a bit overkill compared to just ignoring the views module for this task and doing the query directly in code from a custom module.

Henrik Opel
A: 

The problem you have having is what you actually are doing is to get all the taxonomies that match on every node on your site. A quick hack would be to create a node (doesn't need to actually be published) that contains all of the taxonomy terms, then you could limit the nodes to only that node and you would get a list of all taxonomy terms you want.

Else I would go for one of the options that Henrik Opel suggested, personally I would just make a little custom module for this, and make the queries myself.

Views is a very powerful module, but in some cases, it's actually a lot easier and faster to just do the queries yourself. Especially when the display is not so complicated. You could even use the templates that views has to render your data, if you don't want/need to create your own.

googletorp

related questions