function ct_hotel_get_special_hotels($type = 'latest', $count = 6, $exclude_ids, $district = array())
    {
        $args = array('post_type' => 'hotel', 'suppress_filters' => 0, 'posts_per_page' => $count);
        if (!empty($exclude_ids)) {
            $args['post__not_in'] = $exclude_ids;
        }
        if (!empty($district)) {
            $args['tax_query'] = array(array('taxonomy' => 'district', 'field' => 'term_id', 'terms' => $district));
        }
        if ($type == 'featured') {
            $args = array_merge($args, array('orderby' => 'rand', 'meta_key' => '_hotel_featured', 'meta_value' => '1'));
            return get_posts($args);
        } elseif ($type == 'latest') {
            $args = array_merge($args, array('orderby' => 'post_date', 'order' => 'DESC'));
            return get_posts($args);
        } elseif ($type == 'popular') {
            global $wpdb;
            $tbl_postmeta = esc_sql($wpdb->prefix . 'postmeta');
            $tbl_terms = esc_sql($wpdb->prefix . 'terms');
            $tbl_term_taxonomy = esc_sql($wpdb->prefix . 'term_taxonomy');
            $tbl_term_relationships = esc_sql($wpdb->prefix . 'term_relationships');
            $date = date('Y-m-d', strtotime('-30 days'));
            $sql = 'SELECT hotel_id, COUNT(*) AS booking_count FROM ' . CT_HOTEL_BOOKINGS_TABLE . ' AS booking
			INNER JOIN ' . CT_ORDER_TABLE . ' as _order ON _order.id = booking.order_id';
            $where = ' WHERE (_order.status <> "cancelled") AND (_order.created > %s)';
            if (!empty($district)) {
                $sql .= " INNER JOIN {$tbl_term_relationships} AS tr ON tr.object_id = t1.hotel_id \r\n\t\t\t\t\t\tINNER JOIN {$tbl_term_taxonomy} AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id";
                $where .= " AND tt.taxonomy = 'district' AND tt.term_id =" . esc_sql($district) . ")";
            }
            $sql .= $where . ' GROUP BY booking.hotel_id ORDER BY booking_count desc LIMIT %d';
            $popular_hotel = $wpdb->get_results($wpdb->prepare($sql, $date, $count));
            $result = array();
            if (!empty($popular_hotel)) {
                foreach ($popular_hotel as $hotel) {
                    $result[] = get_post(ct_hotel_clang_id($hotel->hotel_id));
                }
            }
            // if booked room number in last month is smaller than count then add latest hotel
            if (count($popular_hotel) < $count) {
                foreach ($popular_hotel as $hotel) {
                    $exclude_ids[] = ct_hotel_clang_id($hotel->hotel_id);
                }
                $result = array_merge($result, ct_hotel_get_special_hotels('latest', $count - count($popular_hotel), $exclude_ids, $district));
            }
            return $result;
        }
    }
 function shortcode_hotels($atts)
 {
     extract(shortcode_atts(array('title' => '', 'type' => 'latest', 'style' => 'advanced', 'count' => 6, 'count_per_row' => 3, 'district' => '', 'post_ids' => '', 'class' => ''), $atts));
     if (!ct_is_hotel_enabled()) {
         return '';
     }
     $styles = array('advanced', 'simple');
     $types = array('latest', 'featured', 'popular', 'hot', 'selected');
     if (!in_array($style, $styles)) {
         $style = 'advanced';
     }
     if (!in_array($type, $types)) {
         $type = 'latest';
     }
     $post_ids = explode(',', $post_ids);
     $district = !empty($district) ? explode(',', $district) : array();
     $count = is_numeric($count) ? $count : 6;
     $count_per_row = is_numeric($count_per_row) ? $count_per_row : 3;
     $output = '';
     $hotels = array();
     if ($type == 'selected') {
         $hotels = ct_hotel_get_hotels_from_id($post_ids);
     } else {
         $hotels = ct_hotel_get_special_hotels($type, $count, array(), $district);
     }
     if ($style == 'simple') {
         $output = '<div class="other_tours"><ul>';
         foreach ($hotels as $post_obj) {
             $post_id = $post_obj->ID;
             $price = get_post_meta($post_id, '_hotel_price', true);
             $output .= '<li><a href="' . esc_url(get_permalink($post_id)) . '">' . get_the_title($post_id) . '<span class="other_tours_price">' . ct_price($price) . '</span></a></li>';
         }
         $output .= '</ul></div>';
     } else {
         ob_start();
         global $before_list, $post_id;
         $before_list = '';
         if (2 == $count_per_row) {
             $before_list = '<div class="col-md-6 col-sm-6 wow zoomIn" data-wow-delay="0.1s">';
         } elseif (4 == $count_per_row) {
             $before_list = '<div class="col-md-3 col-sm-6 wow zoomIn" data-wow-delay="0.1s">';
         } else {
             $before_list = '<div class="col-md-4 col-sm-6 wow zoomIn" data-wow-delay="0.1s">';
         }
         if (!empty($title)) {
             echo '<h2>' . esc_html($title) . '</h2>';
         }
         echo '<div class="hotel-list row add-clearfix' . esc_attr($class) . '">';
         foreach ($hotels as $post_obj) {
             $post_id = $post_obj->ID;
             ct_get_template('loop-grid.php', '/templates/hotel/');
         }
         echo '</div>';
         $output = ob_get_contents();
         ob_end_clean();
     }
     return $output;
 }