I have a section for Businesses. I also have categories that these businesses can belong to. On each category page I want to list all the businesses that belong to that category. So far so good, but here's the rub: Each business also has an entry field that relates the business to a Town entry.
Businesses belong both to a category and a town entry.
On the category page I want to list the businesses by towns. So instead of having a laundry list of businesses, the businesses would be broken up by the different towns they belong to:
Town A
- Business 1
- Business 2
Town B
- Business 3
Town C
- Business 4
- Business 5
- Business 6
I am grabbing my businesses like this:
{% set businesses = craft.entries.relatedTo(category) %}
I have seen other answers to different questions suggest GROUP, but I'm not sure how to correctly go about using the group method on an array when I am trying to group via another array (entry field).
I tried this, but it results in "Object of class Craft\ElementCriteriaModel could not be converted to string":
{% set businessesByTown = businesses|group('bizTown') %}
I know that's fishy and incorrect, but I don't know how to accomplish it the right way. bizTown
is the entry field I want to sort by.
If anyone could help, that'd be wonderful! Thank you!