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

Pagination No Longer Working after Update to v4.1.0 #188

Open
kmgdevelopment opened this issue Mar 31, 2024 · 1 comment
Open

Pagination No Longer Working after Update to v4.1.0 #188

kmgdevelopment opened this issue Mar 31, 2024 · 1 comment
Labels

Comments

@kmgdevelopment
Copy link

Description

After updating Element API to 4.1.0 the pagination on my endpoints no longer works. Following the "next" link to ?page=2 for example simply returns the page 1 results.

Here's my endpoint code:

return [
    'endpoints' => [
        'recipes.json' => function() {
            $entryCriteria = [
                'section' => 'recipes'
            ];

            // filter by search query
            $searchQuery = Craft::$app->request->getQueryParam('query');
            if($searchQuery) {
                $entryCriteria += [
                    'search' => $searchQuery,
                    'orderBy' => 'score'
                ];
            }

            // filter by category
            $categoryQuery = Craft::$app->request->getQueryParam('category');
            if($categoryQuery) {
                $operator = ['and'];
                $categoryList = explode(' ', $categoryQuery);

                $entryCriteria += [
                    'relatedTo' => array_merge($operator, $categoryList)
                ];
            }

            return [
                'elementType' => Entry::class,
                'elementsPerPage' => 12,
                'criteria' => $entryCriteria,
                'resourceKey' => 'entries',
                'transformer' => function(Entry $entry) {
                    return [
                        'id' => $entry->id,
                        'title' => $entry->title,
                        'uri' => $entry->uri,
                        'recipeImg' => $entry->recipeImg->one()->url
                    ];
                },
                'pretty' => true
            ];
        },
    ]
];

Steps to reproduce

  1. Update Element API from 3.0.1.1 to 4.1.0
  2. Access a query-string paginated page on your endpoint (for example: my-site.tld/endpoint.json?page=2)

Additional info

  • Craft version: 4.8.6
  • PHP version: 8.1.23
  • Database driver & version: MySQL 8.0.33
  • Plugins & versions: Amazon S3 2.2.1; Asset Rev 7.0.0; CKEditor 3.8.3; Super Table 3.0.12
@i-just
Copy link

i-just commented May 2, 2024

Hi, thanks for reaching out! I’m unable to replicate this.

Do you have more than 12 entries matching the criteria? If I only have 12 entries, the results don’t show the pagination link on page 1, but if I manually edit the URL to request page 2, the results from page 1 will be returned.

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

No branches or pull requests

2 participants