2

I am trying to create a view to show content that is tagged with taxonomy terms from the users profile (each vocabulary has its own field in the users profile where the user can select via check boxes what they are interested in.)

I read and watched multiple tutorials and articles on this, and the closest I can get is described here by Triskelion:

create a user view, add relationships: Content: Tags (my Vocab) and Taxonomy term: Content with term with a contextual filter on the User:UID, then display the content:title. This works perfectly given one vocabulary, but I cannot for the life of me get it to work correctly with multiple vocabs.

I added multiples of the above relationships for each of the vocabs, and display multiple content:titles with each relationship, but the problem is that each row in the view will contain only one different title. Aggregation and Querey distinct settings don't seem to help!!

Can anyone point me in the right direction. I know there is a solution to scrap my multiple vocabularies and just put all terms into one but this is not really desirable, as id lose the structure of my taxonomy.

1

If I understood correctly you are trying to eliminate duplicates from your view. Display only one title by content.

When I'm in a case when even Aggregation or Query Distinct settings don't seem to work (most of the time this is caused because the query left/inner joins), I use a small script that does the trick to do an easy group by using the query comment field. In your case you could group by node.id

/**
 *  Found this trick on theoleschool.com.
 *  
 *  Description: Allows the view developer to specify the query
 *  group by action in the query comments. Great way to force the
 *  removal of duplicates.
 *  
 *  Just go into your query comments and type in "groupby:" with
 *  that colon followed by the field you want to group by.
 * 
 *  Examples...
 *  groupby:node.nid
 *  groupby:file_managed_file_usage.fid
 * 
 *  Ref-Comment: http://theoleschool.com/comment/496#comment-496
 *  Ref-Article: http://theoleschool.com/blog/using-hookviewsalter-add-group-statement
 */
function mymodule_query_alter(QueryAlterableInterface $query) {
  if ($query->hasTag('views')) {
    static $count;
    $view =& $query->getMetaData('view');

    if (strstr($groupby = $view->query->options['query_comment'], 'groupby')) {
      list($action, $field) = explode(':', $groupby);

      if (strlen($field) > 0) {
        $query->groupBy($field);
      }
    }
  }
}
  • I took the easy way out and reduced my taxonomy to one single vocabulary which solved the issue. Hopefully your response can help someone else out with the same issue though! – Ed Wilson Oct 29 '15 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.