Stumped: sorting page_list results by a custom attribute, how to control the results count in 5.7?

Permalink
I am using a custom page_list template to sort and filter page results by a custom attribute. In 5.6 I could control the number of page results to display with $pl->get();. I could pass an integer for the number of page results I wanted to display, in 5.7 this doesn't seem to work.

Any assistance would be greatly appreciated.

Example:
<?php
$pl = new PageList();
$pl->filterByCollectionTypeHandle('event_entry');
$datetime = strtotime('-1 day');
$mysqldate = date("Y-m-d H:i:s", $datetime);
$pl->filterbyAttribute('event_date_time', $mysqldate, '>');
$pl->sortBy('ak_event_date_time', 'asc');
// in 5.6 this would control the number of page results to display
// it would get 5 pages that met the filter and sort
// $pl->get(5);
$pages = $pl->get();
?>

MrKDilkington
 
pvernaglia replied on at Permalink Reply
pvernaglia
Just tried, doesn't work for me either
exchangecore replied on at Permalink Reply
exchangecore
The PageList get() function was deprecated. The new way I believe is to use the pagination object (see code snippet) but I'm still not sure you can only get X pages of results.

$pagination = $pl->getPagination();
$pages = $pagination->getCurrentPageResults();


I'm actually not sure why you would only want to get 5 pages here? If it's going to be paginated anyway why limit this here?
MrKDilkington replied on at Permalink Reply
MrKDilkington
"The PageList get() function was deprecated. The new way I believe is to use the pagination object (see code snippet) but I'm still not sure you can only get X pages of results."

Sorry, to be more specific, I am looking to limit the number of results not pages of results.

"$pagination = $pl->getPagination();
$pages = $pagination->getCurrentPageResults();"

I will give this a shot, thank you.

"I'm actually not sure why you would only want to get 5 pages here? If it's going to be paginated anyway why limit this here?"

I often use the page_list without pagination. For example, I might have a home page section that lists the next upcoming 5 events (just the 5, without pagination).
exchangecore replied on at Permalink Best Answer Reply
exchangecore
O gotcha,

I think that you could maybe just set the "MaxPerPage" property, then just pull back the first page yes?

(stab in the dark below)
$pagination = $pl->getPagination();
$pagination->setMaxPerPage(5);
$pages = $pagination->getCurrentPageResults();


Edit: For clarity I simply misunderstood since by "Pages" you were referring to the number of objects in the list, I was stuck on pagination.
MrKDilkington replied on at Permalink Reply
MrKDilkington
$pagination = $pl->getPagination();
$pagination->setMaxPerPage(5);
$pages = $pagination->getCurrentPageResults();

That worked, thank you very much.