diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index 1e557d0bc34..f0821d2c336 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -30,4 +30,5 @@ - Image cleansing now preserves the original image quality, if known. - Fixed a bug where `craft\config\GeneralConfig::safeMode()` set Safe Mode to `false` by default. - Fixed a bug where Craft wasn’t auto-rotating or flipping images uploaded with a mirrored EXIF orientation. +- Fixed a bug where elements weren’t getting returned in a consistent order when `orderBy` was set to `RAND(X)` across varying `limit` param values. ([#16432](https://github.com/craftcms/cms/issues/16432)) - Updated Twig to 3.15. ([#16207](https://github.com/craftcms/cms/discussions/16207)) diff --git a/src/elements/db/ElementQuery.php b/src/elements/db/ElementQuery.php index c0798b58a53..02a9d0ef652 100644 --- a/src/elements/db/ElementQuery.php +++ b/src/elements/db/ElementQuery.php @@ -3051,7 +3051,8 @@ private function _applyOrderByParams(YiiConnection $db): void unset($direction); } - $this->query->orderBy($orderBy); + // No need to set orderBy on $this->query. And doing so breaks RAND(X). + // (see https://github.com/craftcms/cms/issues/16432) $this->subQuery->orderBy($orderBy); }