Answers.Body: <p>You could get the entries ids, then get the categories related to those entries.
  Like so:</p>
  
  <pre><code>{%- set ids= craft.entries.section('sectionHandle').ids() -%}
  
  {%- for cat in craft.categories.relatedTo({ sourceElement: ids }).group('categoryHandle') -%}
      {{- cat.title -}}
  {%- endfor -%}
  </code></pre>
  
  <p>That will only print categories with an entry associated with.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T19:56:55.977Z
Answers.Text: Here's a video that covers a similar approach and also includes adding the entry count with each category. https://craftquest.io/lessons/creating-a-dynamic-category-list
Answers.UserDisplayName: CraftQuest
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-01T18:20:36.193Z
Answers.LastActivityDate: 2019-02-01T18:20:36.193Z
Answers.UserDisplayName: Cryptomothy
Body: <p>I have a set of categories that I would like to display on a sidebar as a way to filter the list of entries displayed. However, some of those categories haven't been associated with any entries yet so clicking on that category with return 0 results. 
  What is the most efficient way to exclude those categories?</p>
  
Tags: <craft3>
Title: Exclude categories that are not associated to any entry
ThreadText: # Exclude categories that are not associated to any entry
  
  (Asked by: username_0 on 2019-02-01)
  
  I have a set of categories that I would like to display on a sidebar as a way to filter the list of entries displayed. However, some of those categories haven't been associated with any entries yet so clicking on that category with return 0 results.
  What is the most efficient way to exclude those categories?
  
  **Tags:** craft3
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-02-01. Score: 1 | Accepted answer
  
  You could get the entries ids, then get the categories related to those entries.
  Like so:
  
  ```
  {%- set ids= craft.entries.section('sectionHandle').ids() -%}
  
  {%- for cat in craft.categories.relatedTo({ sourceElement: ids }).group('categoryHandle') -%}
      {{- cat.title -}}
  {%- endfor -%}
  
  ```
  
  That will only print categories with an entry associated with.
  
  > **Comments:**
  > **username_2**: Here's a video that covers a similar approach and also includes adding the entry count with each category. https://username_2.io/lessons/creating-a-dynamic-category-list  
  
  ---
  
  