Last active
August 29, 2015 14:24
-
-
Save martsie/af08035fbab0fe396cb6 to your computer and use it in GitHub Desktop.
Making views table filters take precedence over sort criteria
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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