Skip to content

[6.x] Add default sorting support for taxonomies#14772

Open
finnjsmith wants to merge 1 commit into
statamic:6.xfrom
finnjsmith:feature/taxonomy-sort-field-direction
Open

[6.x] Add default sorting support for taxonomies#14772
finnjsmith wants to merge 1 commit into
statamic:6.xfrom
finnjsmith:feature/taxonomy-sort-field-direction

Conversation

@finnjsmith
Copy link
Copy Markdown

@finnjsmith finnjsmith commented Jun 3, 2026

Docs issue: statamic/docs#1925

Add sort_by and sort_dir support to Taxonomies

What & Why

Collections support sort_by and sort_dir config options to control the default sort field and direction in the CP listing. Taxonomies have sortField() and sortDirection() methods on the model but they are hardcoded to return 'title' and 'asc' respectively, both marked with // todo comments, and neither key is read from or written to the taxonomy's YAML file.

This means there is currently no way to configure the default sort order of a taxonomy's term listing in the CP.

Changes

  • src/Taxonomies/Taxonomy.php — replaced hardcoded sortField() and sortDirection() methods with fluent getter/setter implementations (mirroring Collection.php), added protected $sortField and protected $sortDirection properties, and updated fileData() to persist sort_by and sort_dir.

  • src/Stache/Stores/TaxonomiesStore.php — updated makeItemFromFile() to hydrate sort_by and sort_dir from the taxonomy YAML (mirroring CollectionsStore.php).

Usage

# content/taxonomies/tags.yaml
title: 'Tags'
sort_by: slug
sort_dir: asc

Notes

There is no UI for this, which is consistent with how Collections handle it — it's a developer-facing config option. The behaviour is otherwise identical to Collections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant