static function get_min_max_price($post_type) { if (empty($post_type) || !TravelHelper::checkTableDuplicate($post_type)) { return array('price_min' => 0, 'price_max' => 500); } $meta_key = 'sale_price'; if ($post_type == 'st_hotel') { $meta_key = 'price_avg'; } $location_text = "id_location"; if ($post_type == 'st_rental') { $location_text = 'location_id'; } global $wpdb; $sql = "\r\n select \r\n min(CAST({$meta_key} as DECIMAL)) as min,\r\n max(CAST({$meta_key} as DECIMAL)) as max"; if ($post_type == 'st_tours' || $post_type == 'st_holidays' || $post_type == 'st_activity') { /*$sql = " select min(CAST(child_price as Decimal)) , min(CAST(adult_price as Decimal)), max(CAST(child_price as Decimal)) , max(CAST(adult_price as Decimal)) " ;*/ $sql = "\r\n select \r\n min(CAST(adult_price as Decimal)), \r\n max(CAST(adult_price as Decimal)) \r\n "; } $sql .= " from {$wpdb->prefix}{$post_type} "; $join = ""; $where = ""; $join .= " join {$wpdb->posts} on {$wpdb->posts}.ID = {$wpdb->prefix}{$post_type}.post_id "; $join = STLocation::edit_join_wpml($join, $post_type); $sql .= $join; $where = " where (1=1 ) "; $where .= "and \r\n (\r\n {$wpdb->posts}.post_status = 'publish'\r\n )\r\n "; $where = STLocation::edit_where_wpml($where); $sql .= $where; //echo $sql; $results = $wpdb->get_results($sql, OBJECT); $array_price = array(); if ($post_type == 'st_tours' || $post_type == 'st_holidays' || $post_type == 'st_activity') { foreach ($results[0] as $key => $value) { $array_price[] = $value; } $price_min = min($array_price); $price_max = max($array_price); } else { $price_min = $results[0]->min; $price_max = $results[0]->max; } if (!$price_max) { $price_max = 500; } // default 0 500 return array('price_min' => ceil($price_min), 'price_max' => ceil($price_max)); }