Sort Page List by custom date attribute2 users found helpful
Anyway, I guess if sortBy() does indeed work, then the other method isn't needed. The default sort order is ascending, so you can omit the second argument in that case.
If you determine that it does indeed work for sure, let us know (and mark the thread as helpful for the benefit of others).
If you want to order PageList output by an attribute you can use the syntax mentioned in your question but changing the words ColletionAttribute with the attribute name you want to sort by.
To order by 'date' attribute use
$pagelist->sortByDate(); or $pagelist->sortByDate('desc');
To order by "my_special_field" attribute use
Remember to form the function name with 'sortBy' and the attribute handle without underlines and with capitalized initials.
$pagelist->sortBy('ak_my_special_attribute'); or $pagelist->sortByMultiple('ak_my_special_attribute desc', 'cName asc');
Just want to highlight to anyone read that you actually do need to put
before the handle of your custom attribute. In my case, my handle was projectSector, so my code was:
$pl->sortByMultiple('ak_projectSector asc', 'cName asc');
If you find out, let me know.
$query = $this->list->getQueryObject(); $query->addOrderBy('ak_my_attribute_handle', 'desc'); // sort by an attribute $query->addOrderBy('cName', 'asc'); // then sort by something directly on the page record $query->addOrderBy('ak_another_att_handle', 'asc');
you can also do it this way
$this->list->sortByMyAttributeHandle('asc'); // normal sort function on a PageList object $query = $this->list->getQueryObject(); $query->addOrderBy('cName', 'asc'); $query->addOrderBy('ak_another_att_handle', 'desc');
But you can't only do the $this->list-> way of sorting once, for additional order clauses you have to use the addOrderBy function on the QueryBuilder object.
This is briefly mentioned onhttps://www.concrete5.org/documentation/developers/5.7/working-with-... under the 'Advanced' section
Thank you for the example.
Any chance you want to make a video or tutorial about it?
i'm a bit confused, i have a custom blog pagelist in bootswatch theme with a custom date from composer. I also want to sort the items on my custom date field.
where can I use the pagelist sort code mentioned above? direct in my blog.php file?
thanks a lot!