-
Notifications
You must be signed in to change notification settings - Fork 22
WIP QueryBuilder pagination #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
6 similar comments
| { | ||
| global $paged; | ||
|
|
||
| if (isset($page)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was missing this feature and stumbled upon this merge request. I quickly checked how it was implemented by curiosity and I might have found an issue here : )
Since the $page attribute has a default value in the function params it will always be set. This means that if the user doesn't pass the $page attribute this will always reset the $paged value to 1.
One solution is to set the $page = NULL in the params and check if $page !== NULL here instead of the isset. I still didn't test it in a real wordpress setup so I might be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, I guess the if is redundant here. I can't see that it would cause any issue but you're right that it will always be set.
I think it's important to provide a default as I can't think of a scenario where when providing no $page param you wouldn't want the first page back.
7c78e56 to
ae4064d
Compare
|
Lumberjack is awesome but really needs this functionality. @joelambert is there a way we can help to get this merged? Pagination is quite helpful 😅. |
|
IMO Code example: |
|
@martinpl I'm not too keen on adding more internal state to the query builder. At the moment @adamtomat do you have any thoughts on this? To my mind, this PR is pretty close, the only question is whether we should write an abstraction around the |
This adds a
paginate()method to the QueryBuilder that returns an instance of Timber'sPostQueryinstead of a Collection.This needs to be tested in a WordPress install.
Possible enhancements could be an abstraction of the
PostQueryclass that gives access to the Pagination object as well as a Collection of posts rather than an Array.