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

OrderBy custom fields does not give correct results #171

Open
TomDeSmet opened this issue Aug 2, 2022 · 2 comments
Open

OrderBy custom fields does not give correct results #171

TomDeSmet opened this issue Aug 2, 2022 · 2 comments
Labels

Comments

@TomDeSmet
Copy link

Description

I'm using Element API to load entries and my criteria includes an orderBy clause that references custom fields (a date field dateFromand a lightswitch availability). The criteria is:

[
    'section' => 'events'
    'dateTo' => [
        0 => 'or'
        1 => '>=2022-08-02'
        2 => ':empty:'
    ]
    'orderBy' => 'dateFrom ASC,availability ASC'
]

When I execute the same query in Twig I get totally differently sorted results:
{% set initialItems = craft.entries.section("events").dateTo(["or", ">=2022-08-02", ":empty:"]).orderBy("dateFrom ASC,availability ASC") %}

The results from twig are correct (they are the same as when I sort by dateFrom in the index in the CP).
The results from Element API don't match. When I use a default field such as postDate or title both return the correct results.

Additional info

  • Craft version: 4.2.0.2
  • PHP version: 8.1.4
  • Database driver & version: MySQL 5
@TomDeSmet TomDeSmet added the bug label Aug 2, 2022
@i-just
Copy link

i-just commented Jan 20, 2023

Hi, thanks for reaching out. I’m having trouble replicating this one. I get the same ordering in twig and via the elements api. Are you still experiencing this issue?

@TomDeSmet
Copy link
Author

Hi there. Yes this is still an issue. We're working on other projects for now, so maybe keep this open en if we come across this again I can hopefully provide you with more leads?

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