I have a content type with one field of type text.

I add content for 5 nodes.

For 2 nodes among 5, I entered nothing in text-field.

So scenario is 3 nodes have data in that field and 2 of the nodes are empty.

Now I'm sorting on behalf of that particular text-field in my custom module and the result is:

It hides node with empty content.

It means only 3 nodes are visible, empty values are not visible.

Expected result should be, the fields that don't have any value inside should also get sorted and the resulting nodes would be seen either at the top of all sort-able content or below it.

How can I achieve this?

2 Answers 2


You can achieve it by installing Views Sort Null Field module.

This module provides an additional sort for FieldAPI fields, which sorts by whether the field is empty or not. This allows empty (i.e. NULL) values in fields to be sorted last.

  • Actually I'm not using views module, it's my custom module where I'm rendering all nodes of certain content type in a block. And I have to sort these rendered nodes on basis of any field. Oct 20, 2015 at 8:59
  • I am using views to query and render a list of nodes, and this module worked a treat, thanks for the answer! Aug 22, 2023 at 11:33

You can may be do ifnull function

IFNULL(node_data_field_value_some.field_important_value,0)  AS node_data_field_value_some_field_important_value

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.