19 June 2011

How to order views programmatically. You might need to do this on special occasions. This hook initializes before query is built so it goes for all data, not just current page.

Source code viewer
  1. function hook_views_query_alter(&$view, &$query)
  2. {
  3. if('view_machine_name' == $view->name)
  4. {
  5. #print the structure
  6. print_r($query);
  7. #order by what ever you need
  8. $query->orderby = array('table_name.column_name DESC');
  9. }
  10. }
Programming Language: PHP