Hi @raphisto,
You can use the undocumented offset
parameter along with limit
(which you already have) for this. It works the same way as MySQL’s OFFSET
parameter.
-
This reply was modified 4 years, 4 months ago by Hector Cabrera. Reason: Fixed typo
I would like to know beforehand how many results there are.
Currently the Query class doesn’t know how many results were found. It wasn’t coded with pagination in mind. If you’re somewhat proficient with PHP and are familiar with WordPress development in general then you may be able to extend the Query class and/or use its internal hooks to have it calculate the total number of results.
I’m pretty sure Laravel expects the object to expose specific methods/properties for it to be able to paginate its results. You’ll need to do some code reading and figure out what is it that Laravel needs for its native pagination function to work with WPP’s Query class and implement that yourself if you want a clean integration between WPP’s Query class and Laravel.
Thanks! it works now.
Oh, I wrote all of the above for nothing then haha.
Might sharing how you made it work @raphisto so future readers can learn too? (and for myself as well as I’m a Laravel enthusiast.)
Thread Starter
Anonymous User 3114766
(@anonymized-3114766)
Hah sorry for that! I created a Collection.php as per this gist:
https://gist.github.com/simonhamp/549e8821946e2c40a617c85d2cf5af5e
And then used it like this:
$collect = ((new \WordPressPopularPosts\Query([
'range' => 'monthly',
'order_by' => 'views',
'post_type' => 'cars',
]))->get_posts());
$popular = (new Collection($collect))->paginate(config('global.perPage'), null, null, 'pages');
Thanks again for the help!
-
This reply was modified 4 years, 4 months ago by Anonymous User 3114766.