Creating a Custom Sort for Collections

Issue

I am unsure how to build a custom sort function for my collections. I have spent quite some time reading through the Query Scopes & Filters page and I have yet to connect the dots on a few things.

Context

I have a collections with a "list" field type, where every item is a year (e.g. 2018, 2019, 2020). I want to sort this collection by the last year in the list.

  1. Should I be using a Scope or a Filter? The documentation does not make this clear to me.
  2. I created a custom scope using php please make:scope SortByYear, and then I tried adding PHP code to simply filter the data (before trying to sort), but I am unable to see any changes in my collection. I don't even know how to USE my newly created scope.

To let you know my experience with Statamic, I have followed the instructions for Creating a Modifier and I got that working. So I feel like creating a custom scope/filter should be fairly similar. The Creating a Modifier page has more thorough descriptions and examples of using your created modifier which makes it easier to understand.

Any and all help is appreciated. Looking forward to learning how this works to unlock more control with Statamic :)

Lloyd

>>>>>>> Unanswered <<<<<<<
8 Replies
3 Followers