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.


1 Answer 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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