echo trav_get_date_format('html'); ?> " class="input-text full-width" value="<?php echo $date_from; ?> " /> </div> </div> <div class="col-xs-6"> <label><?php _e('CHECK OUT', 'trav'); ?> </label> <div class="datepicker-wrap validation-field from-today"> <input name="date_to" type="text" placeholder="<?php echo trav_get_date_format('html'); ?> " class="input-text full-width" value="<?php echo $date_to; ?> " /> </div> </div> </div> </div> <div class="col-md-4"> <h4 class="title"><?php _e('Who', 'trav'); ?> </h4>
function shortcode_search_group($atts, $content = null) { $variables = array('class' => '', 'style' => 'style2'); extract(shortcode_atts($variables, $atts)); global $trav_options, $search_max_rooms, $search_max_adults, $search_max_kids, $def_currency; $all_features = array('acc', 'tour'); $enabled_features = array(); foreach ($all_features as $feature) { if (empty($trav_options['disable_' . $feature])) { $enabled_features[] = $feature; } } ob_start(); ?> <div class="search-box-wrapper <?php echo esc_attr($style . ' ' . $class); ?> "> <div class="search-box"> <?php if (count($enabled_features) > 1) { ?> <ul class="search-tabs clearfix"> <?php if (in_array('acc', $enabled_features)) { ?> <li <?php if ($enabled_features[0] == 'acc') { echo 'class="active"'; } ?> ><a href="#hotels-tab" data-toggle="tab"><i class="soap-icon-hotel"></i> <span><?php _e('HOTELS', 'trav'); ?> </span></a></li> <?php } ?> <?php if (in_array('tour', $enabled_features)) { ?> <li <?php if ($enabled_features[0] == 'tour') { echo 'class="active"'; } ?> ><a href="#tours-tab" data-toggle="tab"><i class="soap-icon-beach"></i> <span><?php _e('TOURS', 'trav'); ?> </span></a></li> <?php } ?> </ul> <div class="visible-mobile"> <ul id="mobile-search-tabs" class="search-tabs clearfix"> <?php if (in_array('acc', $enabled_features)) { ?> <li <?php if ($enabled_features[0] == 'acc') { echo 'class="active"'; } ?> ><a href="#hotels-tab" data-toggle="tab"><?php _e('HOTELS', 'trav'); ?> </a></li> <?php } ?> <?php if (in_array('tour', $enabled_features)) { ?> <li <?php if ($enabled_features[0] == 'tour') { echo 'class="active"'; } ?> ><a href="#tours-tab" data-toggle="tab"><?php _e('TOURS', 'trav'); ?> </a></li> <?php } ?> </ul> </div> <?php } ?> <?php if ($style == 'style2' || $style == 'style4') { ?> <div class="search-tab-content"> <?php if (in_array('acc', $enabled_features)) { ?> <?php if (count($enabled_features) > 1) { ?> <div class="tab-pane fade<?php if ($enabled_features[0] == 'acc') { echo ' active in'; } ?> " id="hotels-tab"> <?php } ?> <h4 class="title"><?php _e('Where do you want to go?', 'trav'); ?> </h4> <form role="search" method="get" id="searchform" class="acc-searchform" action="<?php echo esc_url(home_url('/')); ?> "> <input type="hidden" name="post_type" value="accommodation"> <div class="row"> <div class="form-group col-sm-6 col-md-3"> <input type="text" name="s" class="input-text full-width" placeholder="<?php _e('Enter a destination or hotel name', 'trav'); ?> " /> </div> <div class="form-group col-sm-6 col-md-4"> <div class="row search-when" data-error-message1="<?php echo __('Your check-out date is before your check-in date. Have another look at your date and try again.', 'trav'); ?> " data-error-message2="<?php echo __('Please select current or future dates for check-in and check-out.', 'trav'); ?> "> <div class="col-xs-6"> <div class="datepicker-wrap from-today"> <input name="date_from" type="text" class="input-text full-width" placeholder="<?php _e('Check In', 'trav'); ?> " /> </div> </div> <div class="col-xs-6"> <div class="datepicker-wrap from-today"> <input name="date_to" type="text" class="input-text full-width" placeholder="<?php _e('Check Out', 'trav'); ?> " /> </div> </div> </div> </div> <div class="form-group col-md-5"> <div class="row"> <div class="col-xs-4"> <div class="selector"> <select name="rooms" class="full-width"> <?php $rooms = isset($_GET['rooms']) && is_numeric((int) $_GET['rooms']) ? (int) $_GET['rooms'] : 1; for ($i = 1; $i <= $search_max_rooms; $i++) { $selected = ''; if ($i == $rooms) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . ' ' . ($i == 1 ? __('Room', 'trav') : __('Rooms', 'trav')) . '</option>'; } ?> </select> </div> </div> <div class="col-xs-4"> <div class="selector"> <select name="adults" class="full-width"> <?php $adults = isset($_GET['adults']) && is_numeric((int) $_GET['adults']) ? (int) $_GET['adults'] : 1; for ($i = 1; $i <= $search_max_adults; $i++) { $selected = ''; if ($i == $adults) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . ' ' . ($i == 1 ? __('Guest', 'trav') : __('Guests', 'trav')) . '</option>'; } ?> </select> </div> </div> <div class="col-xs-4"> <button type="submit" class="full-width"><?php _e('SEARCH NOW', 'trav'); ?> </button> </div> </div> </div> </div> </form> <?php if (count($enabled_features) > 1) { ?> </div> <?php } ?> <?php } ?> <?php if (in_array('tour', $enabled_features)) { ?> <?php if (count($enabled_features) > 1) { ?> <div class="tab-pane fade<?php if ($enabled_features[0] == 'tour') { echo ' active in'; } ?> " id="tours-tab"> <?php } ?> <h4 class="title"><?php _e('Where do you want to go?', 'trav'); ?> </h4> <form role="search" method="get" id="searchform" class="tour-searchform" action="<?php echo esc_url(home_url('/')); ?> "> <input type="hidden" name="post_type" value="tour"> <div class="row"> <div class="form-group col-sm-4 col-md-3"> <input type="text" name="s" class="input-text full-width" placeholder="<?php _e('Enter a destination or tour name', 'trav'); ?> " /> </div> <div class="form-group col-sm-8 col-md-4"> <div class="row"> <div class="col-xs-6"> <div class="datepicker-wrap from-today"> <input name="date_from" type="text" class="input-text full-width" placeholder="<?php _e('From', 'trav'); ?> " /> </div> </div> <div class="col-xs-6"> <div class="datepicker-wrap from-today"> <input name="date_to" type="text" class="input-text full-width" placeholder="<?php _e('To', 'trav'); ?> " /> </div> </div> </div> </div> <div class="form-group col-sm-6 col-md-3"> <?php $trip_types = get_terms('tour_type'); ?> <div class="row"> <?php if (!empty($trip_types)) { ?> <div class="col-xs-6"> <div class="selector"> <select name="tour_types" class="full-width"> <option value=""><?php _e('Trip Type', 'trav'); ?> </option> <?php foreach ($trip_types as $trip_type) { ?> <option value="<?php echo $trip_type->term_id; ?> "><?php _e($trip_type->name, 'trav'); ?> </option> <?php } ?> </select> </div> </div> <?php } ?> <div class="col-xs-6"> <input type="text" name="max_price" class="input-text full-width" placeholder="<?php echo sprintf(__('Max Budget (%s)', 'trav'), $def_currency); ?> " /> </div> </div> </div> <div class="form-group col-sm-6 col-md-2"> <button type="submit" class="full-width"><?php _e('SEARCH NOW', 'trav'); ?> </button> </div> </div> </form> <?php if (count($enabled_features) > 1) { ?> </div> <?php } ?> <?php } ?> </div> <?php } elseif ($style == 'style5') { ?> <div class="search-tab-content"> <?php if (in_array('acc', $enabled_features)) { ?> <?php if (count($enabled_features) > 1) { ?> <div class="tab-pane fade<?php if ($enabled_features[0] == 'acc') { echo ' active in'; } ?> " id="hotels-tab"> <?php } ?> <form role="search" method="get" id="searchform" class="acc-searchform" action="<?php echo esc_url(home_url('/')); ?> "> <input type="hidden" name="post_type" value="accommodation"> <div class="title-container"> <h2 class="search-title"><?php _e('Search and Book Hotels', 'trav'); ?> </h2> <p><?php _e("We're bringing you a new level of comfort.", 'trav'); ?> </p> <i class="soap-icon-hotel"></i> </div> <div class="search-content"> <h5 class="title"><?php _e('Where', 'trav'); ?> </h5> <label><?php _e('Your Destination', 'trav'); ?> </label> <input type="text" name="s" class="input-text full-width" placeholder="<?php _e('Enter a destination or hotel name', 'trav'); ?> " /> <hr> <h5 class="title"><?php _e('When', 'trav'); ?> </h5> <div class="row search-when" data-error-message1="<?php echo __('Your check-out date is before your check-in date. Have another look at your date and try again.', 'trav'); ?> " data-error-message2="<?php echo __('Please select current or future dates for check-in and check-out.', 'trav'); ?> "> <div class="col-xs-6"> <div class="datepicker-wrap from-today"> <input name="date_from" type="text" class="input-text full-width" placeholder="<?php _e('Check In', 'trav'); ?> " /> </div> </div> <div class="col-xs-6"> <div class="datepicker-wrap from-today"> <input name="date_to" type="text" class="input-text full-width" placeholder="<?php _e('Check Out', 'trav'); ?> " /> </div> </div> </div> <hr> <h5 class="title"><?php _e('Who', 'trav'); ?> </h5> <div class="row"> <div class="col-xs-4"> <label><?php _e('Rooms', 'trav'); ?> </label> <div class="selector"> <select name="rooms" class="full-width"> <?php $rooms = isset($_GET['rooms']) && is_numeric((int) $_GET['rooms']) ? (int) $_GET['rooms'] : 1; for ($i = 1; $i <= $search_max_rooms; $i++) { $selected = ''; if ($i == $rooms) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . ' ' . ($i == 1 ? __('Room', 'trav') : __('Rooms', 'trav')) . '</option>'; } ?> </select> </div> </div> <div class="col-xs-4"> <label><?php _e('Adults', 'trav'); ?> </label> <div class="selector"> <select name="adults" class="full-width"> <?php $adults = isset($_GET['adults']) && is_numeric((int) $_GET['adults']) ? (int) $_GET['adults'] : 1; for ($i = 1; $i <= $search_max_adults; $i++) { $selected = ''; if ($i == $adults) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . ' ' . ($i == 1 ? __('Guest', 'trav') : __('Guests', 'trav')) . '</option>'; } ?> </select> </div> </div> <div class="col-xs-4"> <label><?php _e('Kids', 'trav'); ?> </label> <div class="selector"> <select name="kids" class="full-width"> <?php $kids = isset($_GET['kids']) && is_numeric((int) $_GET['kids']) ? (int) $_GET['kids'] : 0; for ($i = 0; $i <= $search_max_kids; $i++) { $selected = ''; if ($i == $kids) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . '</option>'; } ?> </select> </div> </div> </div> <div class="age-of-children <?php if ($kids == 0) { echo 'no-display'; } ?> "> <h5><?php _e('Age of Children', 'trav'); ?> </h5> <div class="row"> <?php $kid_nums = $kids > 0 ? $kids : 1; for ($kid_num = 1; $kid_num <= $kid_nums; $kid_num++) { ?> <div class="col-xs-4 child-age-field"> <label><?php echo esc_html(__('Child ', 'trav') . $kid_num); ?> </label> <div class="selector validation-field"> <select name="child_ages[]" class="full-width"> <?php $max_kid_age = 17; $child_ages = isset($_GET['child_ages'][$kid_num - 1]) && is_numeric((int) $_GET['child_ages'][$kid_num - 1]) ? (int) $_GET['child_ages'][$kid_num - 1] : 0; for ($i = 0; $i <= $max_kid_age; $i++) { $selected = ''; if ($i == $child_ages) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . esc_attr($selected) . '>' . esc_html($i) . '</option>'; } ?> </select> </div> </div> <?php } ?> </div> </div> <hr> <button type="submit" class="full-width uppercase"><?php _e('Proceed To Result', 'trav'); ?> </button> </div> </form> <?php if (count($enabled_features) > 1) { ?> </div> <?php } ?> <?php } ?> <?php if (in_array('tour', $enabled_features)) { ?> <?php if (count($enabled_features) > 1) { ?> <div class="tab-pane fade<?php if ($enabled_features[0] == 'tour') { echo ' active in'; } ?> " id="tours-tab"> <?php } ?> <form role="search" method="get" id="searchform" class="tour-searchform" action="<?php echo esc_url(home_url('/')); ?> "> <input type="hidden" name="post_type" value="tour"> <div class="title-container"> <h2 class="search-title"><?php _e('Search and Book Tours', 'trav'); ?> </h2> <p><?php _e("We're bringing you a new level of comfort.", 'trav'); ?> </p> <i class="soap-icon-beach"></i> </div> <div class="search-content"> <h5 class="title"><?php _e('Where', 'trav'); ?> </h5> <label><?php _e('Destination', 'trav'); ?> </label> <input type="text" name="s" class="input-text full-width" placeholder="<?php _e('Enter a destination or tour name', 'trav'); ?> " /> <hr> <h5 class="title"><?php _e('When', 'trav'); ?> </h5> <div class="row"> <div class="col-xs-6"> <label><?php _e('From', 'trav'); ?> </label> <div class="datepicker-wrap from-today"> <input name="date_from" type="text" class="input-text full-width" placeholder="<?php _e('From', 'trav'); ?> " /> </div> </div> <div class="col-xs-6"> <label><?php _e('To', 'trav'); ?> </label> <div class="datepicker-wrap from-today"> <input name="date_to" type="text" class="input-text full-width" placeholder="<?php _e('To', 'trav'); ?> " /> </div> </div> </div> <hr> <!-- <h5 class="title"><?php _e('Trip Type', 'trav'); ?> </h5> --> <div class="row"> <?php $trip_types = get_terms('tour_type'); ?> <?php if (!empty($trip_types)) { ?> <div class="col-xs-6"> <label><?php _e('Trip Type', 'trav'); ?> </label> <div class="selector"> <select name="tour_types" class="full-width"> <option value=""><?php _e('Trip Type', 'trav'); ?> </option> <?php foreach ($trip_types as $trip_type) { ?> <option value="<?php echo $trip_type->term_id; ?> "><?php _e($trip_type->name, 'trav'); ?> </option> <?php } ?> </select> </div> </div> <?php } ?> <div class="col-xs-6"> <label><?php _e('Budget', 'trav'); ?> </label> <input type="text" name="max_price" class="input-text full-width" placeholder="<?php echo sprintf(__('Max Budget (%s)', 'trav'), $def_currency); ?> " /> </div> </div> <hr> <button type="submit" class="full-width uppercase"><?php _e('Proceed To Result', 'trav'); ?> </button> </div> </form> <?php if (count($enabled_features) > 1) { ?> </div> <?php } ?> <?php } ?> </div> <?php } else { ?> <div class="search-tab-content"> <?php if (in_array('acc', $enabled_features)) { ?> <?php if (count($enabled_features) > 1) { ?> <div class="tab-pane fade<?php if ($enabled_features[0] == 'acc') { echo ' active in'; } ?> " id="hotels-tab"> <?php } ?> <form role="search" method="get" id="searchform" class="acc-searchform" action="<?php echo esc_url(home_url('/')); ?> "> <input type="hidden" name="post_type" value="accommodation"> <div class="row"> <div class="form-group col-sm-6 col-md-3"> <h4 class="title"><?php _e('Where', 'trav'); ?> </h4> <label><?php _e('Your Destination', 'trav'); ?> </label> <input type="text" name="s" class="input-text full-width" placeholder="<?php _e('Enter a destination or hotel name', 'trav'); ?> " /> </div> <div class="form-group col-sm-6 col-md-4"> <h4 class="title"><?php _e('When', 'trav'); ?> </h4> <div class="row search-when" data-error-message1="<?php echo __('Your check-out date is before your check-in date. Have another look at your date and try again.', 'trav'); ?> " data-error-message2="<?php echo __('Please select current or future dates for check-in and check-out.', 'trav'); ?> "> <div class="col-xs-6"> <label><?php _e('CHECK IN', 'trav'); ?> </label> <div class="datepicker-wrap from-today"> <input name="date_from" type="text" class="input-text full-width" placeholder="<?php echo trav_get_date_format('html'); ?> " /> </div> </div> <div class="col-xs-6"> <label><?php _e('CHECK OUT', 'trav'); ?> </label> <div class="datepicker-wrap from-today"> <input name="date_to" type="text" class="input-text full-width" placeholder="<?php echo trav_get_date_format('html'); ?> " /> </div> </div> </div> </div> <div class="form-group col-sm-6 col-md-3"> <h4 class="title"><?php _e('Who', 'trav'); ?> </h4> <div class="row"> <div class="col-xs-4"> <label><?php _e('Rooms', 'trav'); ?> </label> <div class="selector"> <select name="rooms" class="full-width"> <?php $rooms = isset($_GET['rooms']) && is_numeric((int) $_GET['rooms']) ? (int) $_GET['rooms'] : 1; for ($i = 1; $i <= $search_max_rooms; $i++) { $selected = ''; if ($i == $rooms) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . '</option>'; } ?> </select> </div> </div> <div class="col-xs-4"> <label><?php _e('Adults', 'trav'); ?> </label> <div class="selector"> <select name="adults" class="full-width"> <?php $adults = isset($_GET['adults']) && is_numeric((int) $_GET['adults']) ? (int) $_GET['adults'] : 1; for ($i = 1; $i <= $search_max_adults; $i++) { $selected = ''; if ($i == $adults) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . '</option>'; } ?> </select> </div> </div> <div class="col-xs-4"> <label><?php _e('Kids', 'trav'); ?> </label> <div class="selector"> <select name="kids" class="full-width"> <?php $kids = isset($_GET['kids']) && is_numeric((int) $_GET['kids']) ? (int) $_GET['kids'] : 0; for ($i = 0; $i <= $search_max_kids; $i++) { $selected = ''; if ($i == $kids) { $selected = 'selected'; } echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . '</option>'; } ?> </select> </div> </div> </div> <div class="age-of-children no-display"> <h5><?php _e('Age of Children', 'trav'); ?> </h5> <div class="row"> <div class="col-xs-4 child-age-field"> <label><?php echo __('Child ', 'trav') . '1'; ?> </label> <div class="selector validation-field"> <select name="child_ages[]" class="full-width"> <?php $max_kid_age = 17; for ($i = 0; $i <= $max_kid_age; $i++) { echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; } ?> </select> </div> </div> </div> </div> </div> <div class="form-group col-sm-6 col-md-2 fixheight"> <label class="hidden-xs"> </label> <button type="submit" class="full-width" data-animation-type="bounce" data-animation-duration="1"><?php _e('SEARCH NOW', 'trav'); ?> </button> </div> </div> </form> <?php if (count($enabled_features) > 1) { ?> </div> <?php } ?> <?php } ?> <?php if (in_array('tour', $enabled_features)) { ?> <?php if (count($enabled_features) > 1) { ?> <div class="tab-pane fade<?php if ($enabled_features[0] == 'tour') { echo ' active in'; } ?> " id="tours-tab"> <?php } ?> <form role="search" method="get" id="searchform" class="tour-searchform" action="<?php echo esc_url(home_url('/')); ?> "> <input type="hidden" name="post_type" value="tour"> <div class="row"> <div class="form-group col-sm-4 col-md-3"> <h4 class="title"><?php _e('Where', 'trav'); ?> </h4> <label><?php _e('Destination ', 'trav'); ?> </label> <input type="text" name="s" class="input-text full-width" placeholder="<?php _e('Enter a destination or tour name', 'trav'); ?> " /> </div> <div class="form-group col-sm-8 col-md-4"> <h4 class="title"><?php _e('When', 'trav'); ?> </h4> <div class="row"> <div class="col-xs-6"> <label><?php _e('From', 'trav'); ?> </label> <div class="datepicker-wrap from-today"> <input name="date_from" type="text" class="input-text full-width" placeholder="<?php echo trav_get_date_format('html'); ?> " /> </div> </div> <div class="col-xs-6"> <label><?php _e('To', 'trav'); ?> </label> <div class="datepicker-wrap from-today"> <input name="date_to" type="text" class="input-text full-width" placeholder="<?php echo trav_get_date_format('html'); ?> " /> </div> </div> </div> </div> <div class="form-group col-sm-6 col-md-3 fixheight"> <?php $trip_types = get_terms('tour_type'); ?> <div class="row"> <?php if (!empty($trip_types)) { ?> <div class="col-xs-6"> <label><?php _e('Trip Type', 'trav'); ?> </label> <div class="selector"> <select name="tour_types" class="full-width"> <option value=""><?php _e('Trip Type', 'trav'); ?> </option> <?php foreach ($trip_types as $trip_type) { ?> <option value="<?php echo $trip_type->term_id; ?> "><?php _e($trip_type->name, 'trav'); ?> </option> <?php } ?> </select> </div> </div> <?php } ?> <div class="col-xs-6"> <label><?php _e('Budget', 'trav'); ?> </label> <input type="text" name="max_price" class="input-text full-width" placeholder="<?php echo sprintf(__('Max Budget (%s)', 'trav'), $def_currency); ?> " /> </div> </div> </div> <div class="form-group col-sm-6 col-md-2 fixheight"> <label class="hidden-xs"> </label> <button type="submit" class="full-width icon-check animated" data-animation-type="bounce" data-animation-duration="1"><?php _e('SEARCH NOW', 'trav'); ?> </button> </div> </div> </form> <?php if (count($enabled_features) > 1) { ?> </div> <?php } ?> <?php } ?> </div> <?php } ?> </div> </div> <?php $output = ob_get_contents(); ob_end_clean(); return $output; }
function trav_acc_get_search_result($s = '', $date_from = '', $date_to = '', $rooms = 1, $adults = 1, $kids = 0, $order_by = 'acc_title', $order = 'ASC', $last_no = 0, $per_page = 12, $min_price = 0, $max_price = 'no_max', $rating = 0, $acc_type, $amenities) { // if wrong date return false if (!empty($date_from) && !empty($date_to) && trav_strtotime($date_from) >= trav_strtotime($date_to)) { return false; } global $wpdb, $language_count; $tbl_posts = esc_sql($wpdb->posts); $tbl_postmeta = esc_sql($wpdb->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'); $tbl_icl_translations = esc_sql($wpdb->prefix . 'icl_translations'); $temp_tbl_name = esc_sql('Search_' . session_id()); $sql = ''; $rooms = esc_sql($rooms); $adults = esc_sql($adults); $kids = esc_sql($kids); $order_by = esc_sql($order_by); $order = esc_sql($order); $last_no = esc_sql($last_no); $per_page = esc_sql($per_page); $min_price = esc_sql($min_price); $max_price = esc_sql($max_price); $rating = esc_sql($rating); if (empty($acc_type) || !is_array($acc_type)) { $acc_type = array(); } if (empty($amenities) || !is_array($amenities)) { $amenities = array(); } foreach ($acc_type as $key => $value) { if (!is_numeric($value)) { unset($acc_type[$key]); } } foreach ($amenities as $key => $value) { if (!is_numeric($value)) { unset($amenities[$key]); } } //mysql escape sting and like escape if (floatval(get_bloginfo('version')) >= 4.0) { $s = esc_sql($wpdb->esc_like($s)); } else { $s = esc_sql(like_escape($s)); } $from_date_obj = date_create_from_format(trav_get_date_format('php'), $date_from); $to_date_obj = date_create_from_format(trav_get_date_format('php'), $date_to); $s_query = ''; // sql for search keyword $c_query = ''; // sql for conditions ( review, avg_price, user_rating ) $v_query = ''; // sql for vacancy check if (!empty($s)) { $s_query = "SELECT DISTINCT post_s1.ID AS acc_id FROM {$tbl_posts} AS post_s1 \n\t\t\t\t\t\tLEFT JOIN {$tbl_postmeta} AS meta_s1 ON post_s1.ID = meta_s1.post_id\n\t\t\t\t\t\tLEFT JOIN {$tbl_terms} AS terms_s1 ON (meta_s1.meta_key IN('trav_accommodation_country','trav_accommodation_city')) AND (terms_s1.term_id = meta_s1.meta_value)\n\t\t\t\t\t\tWHERE (post_s1.post_status = 'publish') AND (post_s1.post_type = 'accommodation')\n\t\t\t\t\t\t AND ((post_s1.post_title LIKE '%{$s}%') \n\t\t\t\t\t\t\tOR (post_s1.post_content LIKE '%{$s}%')\n\t\t\t\t\t\t\tOR (meta_s1.meta_value LIKE '%{$s}%')\n\t\t\t\t\t\t\tOR (terms_s1.name LIKE '%{$s}%'))"; } else { $s_query = "SELECT post_s1.ID AS acc_id FROM {$tbl_posts} AS post_s1 \n\t\t\t\t\t\tWHERE (post_s1.post_status = 'publish') AND (post_s1.post_type = 'accommodation')"; } // if wpml is enabled do search by default language post if (defined('ICL_LANGUAGE_CODE') && $language_count > 1) { $s_query = "SELECT DISTINCT it2.element_id AS acc_id FROM ({$s_query}) AS t0\n\t\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it1 ON (it1.element_type = 'post_accommodation') AND it1.element_id = t0.acc_id\n\t\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it2 ON (it2.element_type = 'post_accommodation') AND it2.language_code='" . trav_get_default_language() . "' AND it2.trid = it1.trid "; } $c_query = "SELECT t1.*, meta_c1.post_id AS room_id, meta_c2.meta_value AS max_adults, meta_c3.meta_value AS max_kids, meta_c4.meta_value AS minimum_stay\n\t\t\t\t\tFROM ( {$s_query} ) AS t1\n\t\t\t\t\tINNER JOIN {$tbl_postmeta} AS meta_c1 ON (meta_c1.meta_key = 'trav_room_accommodation') AND (t1.acc_id = meta_c1.meta_value)\n\t\t\t\t\tINNER JOIN {$tbl_postmeta} AS meta_c2 ON (meta_c1.post_id = meta_c2.post_id) AND (meta_c2.meta_key='trav_room_max_adults')\n\t\t\t\t\tLEFT JOIN {$tbl_postmeta} AS meta_c3 ON (meta_c1.post_id = meta_c3.post_id) AND (meta_c3.meta_key='trav_room_max_kids')\n\t\t\t\t\tLEFT JOIN {$tbl_postmeta} AS meta_c4 ON (t1.acc_id = meta_c4.post_id) AND (meta_c4.meta_key='trav_accommodation_minimum_stay')"; // if this searh has specified date then check vacancy and booking data, but if it doesn't have specified date then only check other search factors if ($from_date_obj && $to_date_obj) { // has specified date $date_interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($from_date_obj, $date_interval, $to_date_obj); $sql_check_date_parts = array(); $days = 0; foreach ($period as $dt) { $check_date = $dt->format("Y-m-d"); $sql_check_date_parts[] = "SELECT '{$check_date}' AS check_date"; $days++; } $sql_check_date = implode(' UNION ', $sql_check_date_parts); $v_query = "SELECT t3.acc_id, t3.room_id, t3.max_adults, t3.max_kids, t3.minimum_stay, MIN(rooms) AS min_rooms FROM (\n\t\t\t\t\t\t\tSELECT t2.*, (IFNULL(vacancies.rooms,0) - IFNULL(SUM(bookings.rooms),0)) AS rooms, check_dates.check_date \n\t\t\t\t\t\t\tFROM ({$c_query}) AS t2\n\t\t\t\t\t\t\tJOIN ( {$sql_check_date} ) AS check_dates\n\t\t\t\t\t\t\tLEFT JOIN " . TRAV_ACCOMMODATION_VACANCIES_TABLE . " AS vacancies ON (vacancies.room_type_id = t2.room_id) AND (vacancies.date_from <= check_dates.check_date AND vacancies.date_to > check_dates.check_date)\n\t\t\t\t\t\t\tLEFT JOIN " . TRAV_ACCOMMODATION_BOOKINGS_TABLE . " AS bookings ON bookings.status!='0' AND (bookings.room_type_id = t2.room_id) AND (bookings.date_from <= check_dates.check_date AND bookings.date_to > check_dates.check_date)\n\t\t\t\t\t\t\tGROUP BY t2.room_id, check_dates.check_date\n\t\t\t\t\t\t ) AS t3\n\t\t\t\t\t\t GROUP BY t3.room_id"; // if rooms == 1 do specific search and if rooms > 1 do overal search for vacancies if ($rooms == 1) { $sql = "SELECT t4.acc_id, SUM(t4.min_rooms) AS rooms FROM ({$v_query}) AS t4\n\t\t\t\t\tWHERE ((t4.minimum_stay IS NULL) OR (t4.minimum_stay <= {$days}))\n\t\t\t\t\t AND (t4.max_adults >= {$adults})\n\t\t\t\t\t AND (t4.max_adults + IFNULL(t4.max_kids,0) >= {$adults} + {$kids})\n\t\t\t\t\tGROUP BY t4.acc_id\n\t\t\t\t\tHAVING rooms >= {$rooms}"; } else { $sql = "SELECT t4.acc_id, SUM(t4.min_rooms) AS rooms, SUM(IFNULL(t4.max_adults,0) * t4.min_rooms) as acc_max_adults, SUM(IFNULL(t4.max_kids,0) * t4.min_rooms) as acc_max_kids FROM ({$v_query}) AS t4\n\t\t\t\t\tWHERE ((t4.minimum_stay IS NULL) OR (t4.minimum_stay <= {$days}))\n\t\t\t\t\tGROUP BY t4.acc_id\n\t\t\t\t\tHAVING rooms >= {$rooms} AND acc_max_adults >= {$adults} AND acc_max_kids >= {$kids}"; } } else { // without specified date $avg_adults = ceil($adults / $rooms); $avg_kids = ceil($kids / $rooms); $sql = "{$c_query} WHERE (meta_c2.meta_value >= {$avg_adults}) AND (meta_c2.meta_value + IFNULL(meta_c3.meta_value,0) >= {$avg_adults} + {$avg_kids}) GROUP BY acc_id"; } // if wpml is enabled return current language posts if (defined('ICL_LANGUAGE_CODE') && $language_count > 1 && trav_get_default_language() != ICL_LANGUAGE_CODE) { $sql = "SELECT it4.element_id AS acc_id FROM ({$sql}) AS t5\n\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it3 ON (it3.element_type = 'post_accommodation') AND it3.element_id = t5.acc_id\n\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it4 ON (it4.element_type = 'post_accommodation') AND it4.language_code='" . ICL_LANGUAGE_CODE . "' AND it4.trid = it3.trid"; } // var_dump($sql); $sql = "CREATE TEMPORARY TABLE IF NOT EXISTS {$temp_tbl_name} AS " . $sql; $wpdb->query($sql); $sql = "SELECT t1.*, post_l1.post_title as acc_title, meta_rating.meta_value as review, meta_price.meta_value as avg_price FROM {$temp_tbl_name} as t1\n\t\t\t\tINNER JOIN {$tbl_posts} post_l1 ON (t1.acc_id = post_l1.ID) AND (post_l1.post_status = 'publish') AND (post_l1.post_type = 'accommodation')\n\t\t\t\tLEFT JOIN {$tbl_postmeta} AS meta_rating ON (t1.acc_id = meta_rating.post_id) AND (meta_rating.meta_key = 'review')\n\t\t\t\tLEFT JOIN {$tbl_postmeta} AS meta_price ON (t1.acc_id = meta_price.post_id) AND (meta_price.meta_key = 'trav_accommodation_avg_price')"; $where = ' 1=1'; if ($min_price != 0) { $where .= " AND cast(meta_price.meta_value as unsigned) >= {$min_price}"; } if ($max_price != 'no_max') { $where .= " AND cast(meta_price.meta_value as unsigned) <= {$max_price} "; } // rating filter if ($rating != 0) { $where .= " AND cast(meta_rating.meta_value as DECIMAL(2,1)) >= {$rating} "; } if (!empty($acc_type)) { $sql .= " INNER JOIN {$tbl_term_relationships} AS tr ON tr.object_id = t1.acc_id \n\t\t\t\t\tINNER JOIN {$tbl_term_taxonomy} AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; $where .= " AND tt.taxonomy = 'accommodation_type' AND tt.term_id IN (" . esc_sql(implode(',', $acc_type)) . ")"; } if (!empty($amenities)) { $where .= " AND (( SELECT COUNT(1) FROM {$tbl_term_relationships} AS tr1 \n\t\t\t\t\tINNER JOIN {$tbl_term_taxonomy} AS tt1 ON ( tr1.term_taxonomy_id= tt1.term_taxonomy_id )\n\t\t\t\t\tWHERE tt1.taxonomy = 'amenity' AND tt1.term_id IN (" . esc_sql(implode(',', $amenities)) . ") AND tr1.object_id = t1.acc_id ) = " . count($amenities) . ")"; } $sql .= " WHERE {$where} GROUP BY acc_id ORDER BY {$order_by} {$order} LIMIT {$last_no}, {$per_page};"; $results = $wpdb->get_results($sql); return $results; }
function trav_tophptime($input_date) { if (!trav_strtotime($input_date)) { return ''; } $return_value = date(trav_get_date_format('php'), trav_strtotime($input_date)); return $return_value; }