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

Fixed order based on slug #190

Closed
thunder87 opened this issue May 13, 2024 · 1 comment
Closed

Fixed order based on slug #190

thunder87 opened this issue May 13, 2024 · 1 comment
Labels

Comments

@thunder87
Copy link

thunder87 commented May 13, 2024

Description

Unable to order entries based on the order the slugs are received.

Steps to reproduce

  1. Copy below entries.json and view the entries.json output in the browser.
  2. Order will be the same regardless of how the slugs are ordered.

Additional info

return [
    'endpoints' => [
        'entries.json' => function() {
            $slugs = Craft::$app->getRequest()->getRequiredQueryParam('slugs');

              return [
                  'elementType' => Entry::class,
                  'criteria' => [
                      'slug' => $slugs
                  ],
                  'transformer' => function (Entry $entry) {
                      return [
                          "title" => $entry->title,
                      ];
                  },
              ];
        }
    ]
]
  • Craft version: 4.9.0
  • PHP version: 8.1.27
  • Database driver & version: MySQL 8.0.33
  • Plugins & versions: Element-api 4.1.0
@thunder87 thunder87 added the bug label May 13, 2024
@i-just
Copy link

i-just commented May 23, 2024

Hi, thanks for reaching out! This is expected behaviour.

By default, entries are ordered by postDate DESC, elements.id DESC. For your entries endpoint, you can provide your own order via criteria > orderBy.

There’s also the fixedOrder option, which might be helpful if you’re querying by ids: https://craftcms.com/docs/4.x/entries.html#fixedorder.

I hope this helps!

@i-just i-just closed this as completed May 23, 2024
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