How to prevent problem with alias when using expose field in hook_views_query_alter()?-Collection of common programming errors

I have some expose fields in my views and I used hook_views_query_alter for changing my sort and also I used my expose field alias in my query alter when user fills my expose field its alias will change in result my query does not work. How can I prevent changing my alias?

This is the error I get:

user warning: Unknown column ‘content_type_adver.field_adver_t_price_value’ in ‘order clause’ query: SELECT DISTINCT node.nid AS nid, node.title AS node_title, node.language AS node_language, node_data_field_adver_t_period.field_adver_star_count_value AS node_data_field_adver_t_period_field_adver_star_count_value, ……

This is my code.

function mysort_views_query_alter(&$view, &$query) {    
  if ($_GET["sortoption"] && $view->name == 'advers_list') {
    $sort = check_plain(trim(strtolower($_GET["sortoption"])));

    switch ($sort) {
      case "posted-desc":
        $query->orderby[0] = 'node_changed DESC';
        break;

      case "posted-asc":
        $query->orderby[0] = 'node_changed ASC';
        break;

      case "price-asc":
        $query->orderby[0] = 'content_type_adver.field_adver_t_price_value ASC';
        break;

      case "price-desc":
        $query->orderby[0] = 'content_type_adver.field_adver_t_price_value DESC';
        break;              

      case "hotel-desc":
        $query->orderby[0] = 'node_data_field_adver_star_count_field_adver_t_hotel_value DESC';         
        break;

      case "hotel-asc":
        $query->orderby[0] = 'node_data_field_adver_star_count_field_adver_t_hotel_value ASC';          
        break;  

      case "end":
        $query->orderby[0] = 'node_title ASC';          
        break;

      case "tripway":
        $query->orderby[0] = 'node_data_field_adver_star_count_field_adver_t_tripway_value ASC';            
        break;                                                          
    }

    $query->orderby[1] = 'node_data_field_adver_star_count_field_adver_star_count_value DESC';
    $query->orderby[2] = 'node_data_field_adver_t_price_exist_field_adver_t_price_exist_value DESC';
    $query->orderby[3] = 'node_changed DESC';
    $query->orderby[4] = '_random ASC';     
  }  
}

Originally posted 2013-11-09 21:42:09.