1

In Craft CMS Twig template I am trying to sort Entries by post date using SuperSort.

An old template on Craft CMS 3.0.17.1 PRO is using:

{% set products = products | supersort('rsortAs', '{ postDate }') %}

And this works as expected.

But after updating to Craft CMS 3.4.17.1 PRO this is throwing an error:

PHP Recoverable Error – yii\base\ErrorException
Object of class DateTime could not be converted to string

I tried updating to:

{% set products = products | supersort('rsortAs', '{ entry.postDate }') %}

But the sorting does not work as expected, ie. nothing is sorted by date.

I saw this Using Supersort with date field but that is not helpful as I am using the latest plugin version.

I'm missing something or doing something wrong?!

1

Figured it out, needed to format the postDate object accordingly:

{% set products = products | supersort('rsortAs', '{ postDate | date("U") }') %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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