Skip to content
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

Allow pagination for custom WP_Query #10

Merged
merged 2 commits into from
Mar 24, 2022
Merged

Conversation

aglipanci
Copy link
Contributor

There are cases where one needs to generate the pagination for a custom WP_Query. Here is an example:

 $postQuery = new WP_Query([
            'post_type' => 'some_custom_post_type',
            // more conditions
        ]);

$pagination = new Pagi();
$pagination->setQuery($postQuery);
$pagination->build();

@Log1x Log1x self-requested a review March 24, 2022 15:25
@Log1x Log1x merged commit 662da66 into Log1x:master Mar 24, 2022
@aglipanci
Copy link
Contributor Author

aglipanci commented Mar 24, 2022

Thank you @Log1x !

@Log1x
Copy link
Owner

Log1x commented Mar 24, 2022

Thank you @Log1x !

Thanks for the PR! :)

@mike-sheppard
Copy link
Contributor

mike-sheppard commented Aug 6, 2022

hey @Log1x & @aglipanci 👋

I might be being silly, but I can't seem to work out how to implement this in a Pagination component. Currently getting Call to undefined method Log1x\Pagi\Pagi::hasPages(). Also, when using PagiFacade the setQuery method doesn't seem to work. Any pointers much appreciated 🙏


View/Components/Pagination.php

namespace App\View\Components;

use Log1x\Pagi\Pagi;
use Roots\Acorn\View\Component;

class Pagination extends Component {

    public $query;

    public function __construct($query = []) {
        $this->query = $query;
    }

    public function render() {
        $pagi = new Pagi();

        if (!empty($this->query)) {
            $pagi->setQuery($this->query);
        }

        $pagi->build();
        return $this->view('components.pagination', ['pagi' => $pagi]);
    }
}

some-template.blade.php

<x-pagination :query="$query" />

@Log1x
Copy link
Owner

Log1x commented Aug 6, 2022

I think you need to pass $pagi->build() to your view.

@mike-sheppard
Copy link
Contributor

yup! nice & easy when you know how :) thanks man 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants