0

I have defined a vocabulary that allows multiple terms to be checked for a Content Type and I would like to create a View that could gather all the data from that Content Type but grouping the results by a specific term.

When I'm not applying any contextual filter, the result list should contain a group of data for every term in my vocabulary. Naturally, some of the items will appear in multiple groups because of the multiple terms scenario.

I would like to create a contextual filter for a specific term and get as a result only one of those groups. The problem is that I'm getting not only the group I expect but other groups in which some of the results have more than one term selected for the same vocabulary.

For example:

  • Content type is "Dogs".
  • Vocabulary is "Places".
  • Taxonomy terms for "Places" are: "Kitchen", "Living room", "Garage", "Outside".

"Dogs" has a field called "Places to play with my owner" which is related to "Places" and the user can select one or more options.

I created a view that has:

  • A relationship with "Places" vocabulary.
  • A contextual filter that retrieves all the "Dogs" that play on each of those places when there is no specific term to filter.
  • A field group using the "Places" term names.

And retrieves the following results on a URL like: /dogs/places-to-play/:

  • Kitchen: Dog A, Dog B.
  • Living Room: Dog A.
  • Garage: Dog C.
  • etc.

The contextual filter should receive a "Places" term name via URL like: /dogs/places-to-play/kitchen and the expected result would be:

  • Kitchen: Dog A, Dog B.

But in my case, the results are:

  • Kitchen: Dog A, Dog B.
  • Living Room: Dog A.

Because "Dog A" has options "Kitchen" and "Living Room" selected in its "Places to play" field.

The question is: Is there a way to avoid getting the extra groups?

Thanks in advance.

4
  • 1
    Hello! I'm trying to reproduce this and am unable. Here's what I have: 1. A Content Type, Dogs, with a taxonomy reference field (field_places) allowing unlimited values from my Places vocabulary. 2. A view to show Dogs content. 3. The fields displayed are Title and field_places. field_places is set to be excluded from the display and it has "Display all values in the same row" unchecked. 4. The view is set to group content based on the rendered value of the field_places field. 5. A contextual filter on field_places (with all default settings, I didn't change anything there).
    – sonfd
    Jan 15, 2021 at 20:28
  • 1
    With the above, I get your expected behavior. I see content grouped by the places tags, with some titles appearing under multiple places, but no places appear more than once. I have no Relationship in this view since it doesn't need one as described, but even if I add a relationship to "Taxonomy term referenced from field_places", I don't see the duplicate results you mention.
    – sonfd
    Jan 15, 2021 at 20:31
  • 1
    I meant to also mention that if I pass a value to the contextual filter I see just the results for that tag, no other tags.
    – sonfd
    Jan 15, 2021 at 20:38
  • @sonfd, thanks for your reply and the time you invested replicating my example! Fortunately, reading how you did it made me realize that I didn't need the relationship to group my results in the first place.
    – pazitos10
    Jan 15, 2021 at 21:14

1 Answer 1

0

To solve the problem:

  1. Removed the relationship with "Places" vocabulary and used the field "Places to play" to create the field groups, checking the "Use rendered output for a group of rows" option.
  2. Unchecked the "Display all values in the same row" option for "Places to play" field.
  3. Created a contextual filter for "Places to play" field to receive the value via URL.

As a result I now get what I was expecting.

2
  • I didn't need the distinct option in my view.
    – sonfd
    Jan 15, 2021 at 21:33
  • @sonfd, once again you are right! thank you very much. I'll edit the answer.
    – pazitos10
    Jan 15, 2021 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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