i have overwritten a field's output, and want to use it as the Sort criteria. so i must overwrite the Sort criteria? is there a way to overwrite the views module Sort criteria?

the sort criteria is:

table votingapi_vote, the field content_id,which is $node->nid, the vaule=1. i want to to sort it by the number counts of the vaule. desc. HOW TO do it?

if i want to alter the sort criteria in the template.php, is there a way to get it?

1 Answer 1


Sure, just use hook_views_query_alter().
You can intercept the view's query object and make any changes you need to it, including (but not limited to) adding/removing sort criteria.

Better WHERE's for your Drupal forums with hook_views_query_alter and Using hook_views_query_alter to change your views sort order give some examples of how to alter a view query.

  • i don't know how to use this hook,could you give me an example. thank you.
    – enjoylife
    Commented Apr 21, 2011 at 6:34
  • Alex, i have updated the question. could you tell me how to use the hook_views_query_alter(). thank you.
    – enjoylife
    Commented Apr 21, 2011 at 7:08
  • Just an FYI, none of your links are working... Commented May 24, 2017 at 23:20

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.