Rareloop / lumberjack

Lumberjack is a powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code.
https://lumberjack.rareloop.com
MIT License
371 stars 34 forks source link

Access correct pagination information when using the Query Builder #33

Closed lmartins closed 1 year ago

lmartins commented 1 year ago

Not sure if I'm missing something in the docs, but I couldn't locate an answer to this on the site.

Can't seem to be able to get pagination to work properly when using the query builder.

With a query like:

  $query = Post::builder()->limit(9);
  $context['posts'] = $query->get();

I've went on to try accessing posts.pagination, that didn't worked, and lastly tried to build out the pagination object using Timber's own method by passing that QueryBuilder params, like this:

  $query = Post::builder()->limit(9);
  $context['posts'] = $query->get();
  $context['pagination'] = Timber::get_pagination($query->getParameters());

This, while creating a pagination object, does not seem to interact with the query from Lumberjack, as navigating to different pages has no effect on the posts being listed (always shows the posts from page 1).

When using Timber's default query methods, as follows, pagination works properly:

   $queryArgs = array(
      'post_type' => 'post',
      'posts_per_page' => 9,
      'paged' => get_query_var('paged') ?: 1,
    );
    $context['posts'] = new \Timber\PostQuery($queryArgs);

Am I missing obvious here? Thank you!

lmartins commented 1 year ago

Going to answer my own question in the hope this may be useful to someone.

Apparently the way to achieve this would be:

    $query = Post::builder()->limit(9)->orderBy('date_published', 'desc');
    $context['posts'] = $query->get();
    $context['pagination'] = Timber::get_pagination($query->getParameters());

Would be great to get some update on the status of Lumberjack. Project appears to be stale judging from the activity on this repo, so any info would be awesome. Thank you.