Creating a view which lists all taxnomy terms and the number they appear in a content type?

drupal.stackexchange https://drupal.stackexchange.com/questions/294018

  •  25-02-2021
  •  | 
  •  

Question

So i have a taxonomy called Product Warnings, and it has around 10 terms. This taxonomy is referenced in several content types (Small products, Large products, etc), and can be selected multiple times (so a user can select in the content type 1 or up to all 10 terms from the Taxonomy).

I want to create a view which lists all terms from the given taxonomy (that's the easy part), and also count the number of times each terms is referenced in a specific content type (i.e. Small products)

So it would look like:

Eye damage: 44
Skin irritation: 13
Hair lose: 1 
.
.
.

Now, this is fairly easy to do with a db_query and custom code, but the trick is to do it in a view (if it's possible)

Was it helpful?

Solution

Found the answer i was looking for, and that is to turn on Field Aggregation from the 3rd panel in the view.

OTHER TIPS

I am not sure if it is possible to get that in a view but I know you can make a view to show content of all types, display only fields - taxonomy terms. Then, you should be able to use aggregation and count each terms occurence. Might not be the best solution tho as this one can drastically decrease the performance of that view since it counts each node.

I think you need to enable the aggregation in the view. the video here explains the same issue but in Drupal 7, but it's okay, it is the same for Drupal 8

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top