Sorting Entries field results by category I have an entries field 'physicians'. I want to output the selections from that field and sort them by category (also named 'physicians') - with the category heading above each category group. 

I can't figure out if I should just output the category list and filter the result by the field or if I should output the entries field and then sort them by category. I'm trying the latter right now but not sure of how to get the categories to work. 

{% set phyGroup = craft.categories.group('physicians') %}
{% set phyList = craft.entries.relatedTo('physicians').order('lastName asc') %}

{% for physicians in phyGroup %}
   &lt;h3&gt;{{ category }}&lt;/h3&gt;
   {% for entry in phyList %}
      {{ entry.lastName }} ...
   {% endfor %}
{% endfor %}
It’s not totally clear from your question where you’re building the relation to the categories,
but I have a feeling that this is the solution you’re looking for.

{% set groupParam = '{ object.categoriesFieldHandle.first() ? object.categoriesFieldHandle.first().title : "No categories" }' %}
{% for groupTitle, entriesInGroup in entry.entriesFieldHandle|group(groupParam) %}
    {{ groupTitle }}

    {% for entry in entriesInGroup %}
        {{ entry.title }}
    {% endfor %}
{% endfor %}