How to use contextual filters to a View for use as a sort criteria? I want a View with a default sort criteria that can be overridden by a contextual filter.  For example, the URL might end like this: ?sort=popular.  popular would be associated with one field and recent, the default, would be associated with another field.
This is on Drupal 7 and Views 3.
I am not sure how this translates to Drupal 7 and Views 3, but I have done the following with Drupal 6 and Views 2 using hook_views_query_alter

function mymodule_views_query_alter (&amp;$view, &amp;$query)
{
    if ($_GET["sort"]) {
        $sort = check_plain(trim(strtolower($_GET["sort"])));

        switch ($sort) {
            case "title":
                $query-&gt;orderby = array("node.title ASC");
                break;
            case "order":
                $query-&gt;orderby = array("node.nid DESC");
                break;
            case "somefield":
                $query-&gt;orderby = array("node_data_field_somefield_field_somefield_value ASC");
                break;
        }
    }
}


The trick is to make the views w/ the sorts, and look at the SQL, and use this to update your code.