Answers.Body: <p>This is a bit brute-force but you can loop all the elements and then check their related count:</p>
  <pre><code>{% for row in craft.entries.section('foo').all() %}
     {% if row.myRelatedField.count() == 10 %}
        &lt;li&gt;{{ row.title }}&lt;/li&gt;
     {% endif %}
  {% endfor %}
  </code></pre>
  <p>You may want to eager-load myRelatedField to save an expensive database query.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-27T11:59:24.523Z
Answers.LastActivityDate: 2021-08-27T11:59:24.523Z
Answers.UserDisplayName: gioppe
Body: <p>does anyone know if there's a way to display a type of &quot;most popular categories&quot; list? It's not exactly my use-case, but it's very similar</p>
  <p>Essentially, I want to be able to have users search for elements with a certain number of relations. I saw an article about using Preparse but these are being maintained by front-end users and I don't want to have to wait for someone to save the parent element to have an accurate count.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-27T13:27:01.227Z
Comments.Text: Would this work for your case - https://craftcms.stackexchange.com/a/37188/3630 ?
Comments.UserDisplayName: Oli
Tags: <templating><relations>
Title: Sorting Categories/Entries by # of relations dynamically
ThreadText: # Sorting Categories/Entries by # of relations dynamically
  
  (Asked by: username_0 on 2021-08-26)
  
  does anyone know if there's a way to display a type of "most popular categories" list? It's not exactly my use-case, but it's very similar
  
  Essentially, I want to be able to have users search for elements with a certain number of relations. I saw an article about using Preparse but these are being maintained by front-end users and I don't want to have to wait for someone to save the parent element to have an accurate count.
  
  **Tags:** templating, relations
  
  > **Comments:**
  > **username_1**: Would this work for your case - https://craftcms.stackexchange.com/a/37188/3630 ?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-08-27. Score: 1
  
  This is a bit brute-force but you can loop all the elements and then check their related count:
  
  ```
  {% for row in craft.entries.section('foo').all() %}
     {% if row.myRelatedField.count() == 10 %}
        <li>{{ row.title }}</li>
     {% endif %}
  {% endfor %}
  
  ```
  
  You may want to eager-load myRelatedField to save an expensive database query.
  
  
  ---
  
  