Drupal 7 Views - How to sort by Grouping Field according to Taxonomy Term ordering, whether custom or by a specific order
Scenario: You have a Views page or block that needs to display contents which are grouped or categorized/classified by a taxonomy term. In my case I have a list of contents (content type sponsors) that needs to be grouped and displayed in this order: Major Sponsors, Partners, Sponsors. For example in above screenshot.
How to display and group content items by your taxonomy terms
- Under Fields, create/insert a field that points to your taxonomy terms; you may want to exclude it from display or use it, depending on your display requirement. This maybe a term reference you have configured in your content type.
- On your Views Format, click on Settings (example: Format: Fluid Grid | Settings)
- Under Grouping field, select the field that references to your taxonomy term/s (example: Content: Category, a term and field created for this requirement)
How to custom or manual sort / order your groupings in Views
After this step you may find your groupings (terms) may not be sorted according to your requirement (whether alphabetical, priority, or any custom ordering). The ordering you may see at this point will depend on many factors and default settings - example, the term ordering (term ID, name) in your vocabulary taxonomy, or perhaps it has no sorting order set at all. Therefore, you may need to do the following to control ordering.
- Create a Relationship > Content: Taxonomy terms on node
- Under Filter Criteria, use this relationship and use Configure field: Taxonomy term: Rendered Taxonomy term
- Under Sort Criteria, (term) Taxonomy term: Name (asc). This is the relationship created and used in the filtering. This ensures that any ordering you make in the term listing gets followed accordingly by ascending or descending.
- Add any secondary sorting as needed. In this requirement, besides ordering by grouped terms, I need to ensure sorting in each group can be customized or sorted manually by user which follows a created sort/ordering weight field. And in case user does not enter any preferred weight sorting, will fall back to default title alphabetical sorting (third and last sort criteria)
Additional reference: https://www.drupal.org/project/views/issues/1239278#comment-6583454