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

[5.x] Fix ordering search results by date #10939

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

duncanmcclean
Copy link
Member

This pull request fixes an issue where it wasn't possible to order entry search results by date.

Essentially, when you order search results, it uses the DataCollection::multisort() method to perform the ordering. As part of that, it tries to get the value of the date field using this code below:

$value = (method_exists($item, $method))
? call_user_func([$item, $method])
: $item->get($sort);

The ->get() here defers to the Result::get() method, which will do ->get('date') on the entry. However, since dates aren't part of an entry's data, it was trying to order results by null.

This PR fixes that by checking if the $key is date and deferring to the entry's date method instead.

Fixes #10892.

@jasonvarga jasonvarga merged commit 5757396 into 5.x Oct 11, 2024
17 checks passed
@jasonvarga jasonvarga deleted the fix/ordering-search-results-by-date branch October 11, 2024 13:41
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.

Search - can't sort by date
2 participants