Sorting page-list with custom Atribute

Permalink
It's seems impossible with the PageList, to sort result with a custom attribute Date.. ? That's strange !

sebastienj
 
hutman replied on at Permalink Reply
hutman
Are you trying to do this with 5.6 or 5.7 and are you using the Page List block or the PageList within your controller/view?
sebastienj replied on at Permalink Reply
sebastienj
I'm using 5.7 and using the PageList programmatically (in a controller)
hutman replied on at Permalink Reply
hutman
I think you should be able to do something like this

$pl = new PageList();
$pl->filterByAttribute('test_date', '', '<>');
$pl->sortByTestDate();
$pages = $pl->get();


Where your attribute handle is 'test_date' this will give you only pages where test_date is not blank and order them ascending
sebastienj replied on at Permalink Reply
sebastienj
I has tryed something like this but i get this error :

An exception occurred while executing 'SELECT p.cID FROM Pages p LEFT JOIN PagePaths pp ON (p.cID = pp.cID and pp.ppIsCanonical = true) LEFT JOIN PageSearchIndex psi ON p.cID = psi.cID LEFT JOIN PageTypes pt ON p.ptID = pt.ptID INNER JOIN Collections c ON p.cID = c.cID LEFT JOIN CollectionSearchIndexAttributes csi ON c.cID = csi.cID INNER JOIN CollectionVersions cv ON p.cID = cv.cID and cvIsApproved = 1 WHERE (ak_date <> ?) AND (p.cPointerID < 1) AND (p.cIsTemplate = 0) AND (p.cIsActive = ?) AND (p.cIsSystemPage = ?) ORDER BY date asc' with params ["", true, false]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'date' in 'order clause'
hutman replied on at Permalink Reply
hutman
Can you provide your code?