Search code examples
drupal-7view

Sorting Drupal view by date but place expired items at the bottom?


I have a view that lists items that have "expiry" dates. For example:

Item 1: Expired yesterday [EXPIRED]
Item 2: Expires in an hour [NOT EXPIRED]
Item 3: Expires in 5 hours [NOT EXPIRED]

If I order by data asc, I get this order. The problem is, I want:

Item 2: Expires in an hour [NOT EXPIRED]
Item 3: Expires in 5 hours [NOT EXPIRED]
Item 1: Expired yesterday [EXPIRED]

So that all expired items fall to the bottom.

I would imagine I need to somehow create another field that indicates "expired" and then sort by that too, but I don't know how to sort by a "generated" field, if you know what I mean?


Solution

  • I solved this by using the Drupal Computed Field module. I added this to my product and then simply sorted by it on the views.