Pagination ignored

Hey there!

I am trying to do some filtering and pagination on a listing-page. In the panel I do have a pages-field, where I can select a source-page. Its listed children should then be shown (if their pub-date is not in the future). I’ve got a range slider for setting the amount of childs shown per page. Now I am trying to do this:

$articles = $page->sourcePages()
		->toPages()
		->children()
		->listed()
		->filter(function ($child) { return $child->date()->toDate() <= time(); })
		->paginate($page->maxsubpages());

sourcePages() is the pages-field in the panel
maxsubpages is the range-slider

But whatever I set within paginate() nothing changes. I also tried it without the maxsubpages field and putting in an int directly. I am pretty sure it worked some time ago, but i might be wrong.

Can someone give me a hint, what I am doing wrong?

Thanks!

Hi,
first i would test if your fields produce the needed output data.
For this you can use dump(). And than I would take out the filter becuse it makles the debugging complexer. Simplify your query for debugging is my consulting.

What type of field is sourcePages()and maxsubpages()?

Cheers

What is the result you are getting at the moment?

Hey,

thank you, that was a good hint!
maxsubpages() was a range-field and the solution was to not just use its return-value but to convert it using ->toInt().

		$articles = $page->sourcePages()
		->toPages()
		->children()
		->listed()
		->filter(function ($child) { return $child->date()->toDate() <= time(); })
		->paginate($page->maxsubpages()->toInt());

Doing so, works perfectly :slight_smile:
Without doing so the field returns object(Kirby\Cms\Field)#19 (1) { ["maxsubpages"]=> string(1) "6" }

Maybe that’s a good point for the docs, so we know, we have to convert it first.

Using the field without converting it (see my other comment) just resulted in no pagination at all.