i have a View that provides a list of products(content type Product). This view has two sort criteria. The one is the "SKU" and the second is "New product". The "New product" is a List(float) field and the available options are N/A, Yes and No.

The view must show first the new products and then all the rest. New products are considered those that they have selected the option "Yes".

Is this possible? Any idea?


1 Answer 1


You can do it using views_query_alter. Find out what are the key values being stored from your list and then use them accordingly in the code below.

function yourmodule_views_query_alter(&$view, &$query) { 
  if ($view->name == 'shop' && $view->current_display == 'page') {
     $query->orderby[0] = array(
           'field' => 'CASE table.type WHEN '1' THEN 1 WHEN '0' THEN 2 WHEN    
            ELSE 3 END');
  • Hi, as i am not programmer could you please tell me the exact syntax? The field is : field_new_product with values 0|NO 1|YES View name : shop Machine name : page Thanks
    – drupspark
    Commented Jun 27, 2014 at 12:34
  • Have a look at drupal.org/node/1074360 to learn how to create your modules.
    – Gokul N K
    Commented Jul 1, 2014 at 6:02

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.