I have a view that filters nodes by a contextual filter that allows multiple values. So it gets a list of node IDs like 234, 235, 210, 56, 78. Is it possible to sort the result of this view according to the order of the given IDs? I tried to achieve that by deleting all sort criteria, but this leads to an arbitrary order of the results.

2 Answers 2


The Views Arguments Extras module (for Drupal 7) seems to do what you are looking for. According to the module page, it provides the following:

Argument Order Sort

a sort handler, that allows for the order of items to be based on their order in a multi-value argument

This particular component is ported to Drupal 8: Views Argument Order Sort:

Using this module will give you a new sort type with a variety of options where you can choose what field to apply the argument values to for sorting.


When you provide a contextual filter with multiple values, views generates a query that has something like this WHERE (node_field_data.nid IN('72586', '60952', '72516', '50611', '60328', '49852', '49819', '49816', '60609', '49834', '60220', '50841'))

Views is doing everything properly, however SQL will effectively sort it from lowest to highest integer.

You need to alter the query to something like this here: https://stackoverflow.com/questions/4858828/sql-where-in-sort-by-order-of-the-list

to achieve the sort you want.

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.