Body: <p>Is there a way to get a list of categories with the number of entries associated with each particular category?</p>
  <p>I want to output something like this:</p>
  <p><a href="https://i.sstatic.net/sxKdz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sxKdz.png" alt="number of hits per category" /></a></p>
  <p>It would make sense to fetch the number of hits in the same DB query. But currently I get the hits by running a <code>craft.products(itemParams).total()</code> per category iteration.</p>
  <p>Or is this not a real performance problem?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-14T15:21:37.563Z
Comments.Text: I'm guessing these totals will change depending on filters, so caching's not an option?
Comments.UserDisplayName: dmatthams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-14T19:02:50.860Z
Comments.Text: Yup, but I am using query string parameters, so each unique filter combination is cacheable. Am using caching now. Just asking more out of curiosity as to whether I can do these kinds of queries.
Comments.UserDisplayName: nitech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-15T10:29:49.987Z
Comments.Text: Do you have multiple categories per products?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-15T10:58:38.640Z
Comments.Text: Yes, and multiple product types
Comments.UserDisplayName: nitech
Tags: <categories><performance>
Title: Get categories with number of hits (entries, products)
ThreadText: # Get categories with number of hits (entries, products)
  
  (Asked by: username_0 on 2020-12-14)
  
  Is there a way to get a list of categories with the number of entries associated with each particular category?
  
  I want to output something like this:
  
  [![number of hits per category](https://i.sstatic.net/sxKdz.png)](https://i.sstatic.net/sxKdz.png)
  
  It would make sense to fetch the number of hits in the same DB query. But currently I get the hits by running a `craft.products(itemParams).total()` per category iteration.
  
  Or is this not a real performance problem?
  
  **Tags:** categories, performance
  
  > **Comments:**
  > **username_1**: I'm guessing these totals will change depending on filters, so caching's not an option?  
  > **username_0**: Yup, but I am using query string parameters, so each unique filter combination is cacheable. Am using caching now. Just asking more out of curiosity as to whether I can do these kinds of queries.  
  > **username_2**: Do you have multiple categories per products?  
  > **username_0**: Yes, and multiple product types  
  
  ---
  
  ## 0 answers
  
  