0

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?

1

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.

1
  • 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 '15 at 8:59
0

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, privacy policy and cookie policy

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