How to sort entries by their descendant count? I want to sort (and paginate) entries from a structure section based on the number of descendants. This is the effective criteria I want to query:

craft.entries.section('myStructure').level(1).order('descendants desc')


Since getDescendants.count() is not a number stored against each entry in the database (AFAIK), how does one go about getting this result?
You could use a Preparse field to calculate and store that value.

The only downside is, it'll only do that calculation when you save the parent entry. So if you add another descendant, you'd have to go back and re-save the parent entry to re-calculate the value.


  Pro tip: You can go to Settings &gt; Sections and re-save the section you are working with. This will automatically trigger a re-save of every single entry in that section.