Skip to content

Instantly share code, notes, and snippets.

@martsie
Last active August 29, 2015 14:24
Show Gist options
  • Save martsie/af08035fbab0fe396cb6 to your computer and use it in GitHub Desktop.
Save martsie/af08035fbab0fe396cb6 to your computer and use it in GitHub Desktop.
Making views table filters take precedence over sort criteria
<?php
/**
* Implements hook_views_query_alter().
*
* By default, views will make sort criteria take precedence over views table sorts when
* "Override normal sorting if click sorting is used" is unticked. This is not ideal when
* you want the user initiated sorting to be secondary sorted on another column.
*/
function hook_views_query_alter(&$view, &$query) {
// Reverse the query order. Note if you have more than one sort criteria,
// that will be reversed as well.
if ($view->name == 'my_view') {
$query->orderby = array_reverse($query->orderby);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment