How to override the default category product collection to show random products on the category page in Magento 2? Also, sort-by should be work when it selected. Could someone help me with this issue?

1 Answer 1


Add the Below code in your list.phtml file,

$_productCollection = $_productCollection->getSelect()->orderRand();
  • I tried this but not working. Commented Feb 10, 2021 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.