I'm working with a Structure of resort locations. Each resort has a field address
which is a Smart Map field. I'm trying to create an initial display page that groups the resorts based on their state (a Smart Map address part), but I would like to order the output first based on the state and then by resort title.
Something like.
- Arkansas
- Awesome Place
- Best Place
- Alabama
- Alright Place
- Better Place
- Florida
I'm partially there using the following:
{% set resorts = craft.entries().section('resortsList').orderBy('title ASC').all() %}
{% set resortsByState = resorts|group('address.state') %}
And then outputting the list...
{% for state, resortsInState in resortsByState %}
<h2>{{ state }}</h2>
{% for resort in resortsInState %}
<p>{{ resort.link }} - {{ resort.address.state }}</p>
{% endfor %}
{% endfor %}
This gives me the list grouped by the state and ordered by the resort title which gets me partially there. I've tried adding address.state
as part of the ordering declaration, but I'm only getting errors (Unknown column 'address.state' in 'order clause'). Is there a proper way I should be doing this?