Ia am working on a view that displays search results for nodes of a certain content type. In this Content Type there is a field "photo". Some of the nodes have a photo, some of them not. Is it possible to display (in the search results), first the nodes that have that field filled and at the bottom the nodes where the field photo is not set?

I tried to achieve it with custom sorting in the PHP field, using a snippet that i found here : https://drupal.org/node/727418#comment-3827246

$query->orderby = "CASE WHEN myFieldName IS NULL THEN 0 END, myFieldName ASC"; }

but it didn't work. Any ideas?


Why not order by quantity of elements in photo field, or delta ?

  • Thanks mate. Your answer that led me to the right direction. There is no field "photo" to choose at sort criteria. But there is photo:width or photo:height. So, with a descending sorting - since empty photos have no width- , you could have the desired output. May 9 '14 at 11:27

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.