I am looking to output the child categories of a parent category. I only need to show the categories which have entries related to them.
I have done this to show all categories using
{% set entryIds = craft.entries.section('stories').ids() %}
{% set categories = craft.categories.relatedTo({ sourceElement: entryIds }).groupId(2).orderBy('title').all() %}
What is the best way to do this for subcategories.