function ct_tour_get_special_tours($type = 'latest', $count = 6, $exclude_ids, $tour_type = array()) { $args = array('post_type' => 'tour', 'suppress_filters' => 0, 'posts_per_page' => $count); if (!empty($exclude_ids)) { $args['post__not_in'] = $exclude_ids; } if (!empty($tour_type)) { $args['tax_query'] = array(array('taxonomy' => 'tour_type', 'field' => 'term_id', 'terms' => $tour_type)); } if ($type == 'featured') { $args = array_merge($args, array('orderby' => 'rand', 'meta_key' => '_tour_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 tour_id, COUNT(*) AS booking_count FROM ' . CT_TOUR_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($tour_type)) { $sql .= " INNER JOIN {$tbl_term_relationships} AS tr ON tr.object_id = t1.tour_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 = 'tour_type' AND tt.term_id =" . esc_sql($tour_type) . ")"; } $sql .= $where . ' GROUP BY booking.tour_id ORDER BY booking_count desc LIMIT %d'; $popular_tour = $wpdb->get_results($wpdb->prepare($sql, $date, $count)); $result = array(); if (!empty($popular_tour)) { foreach ($popular_tour as $tour) { $result[] = get_post(ct_tour_clang_id($tour->tour_id)); } } // if booked room number in last month is smaller than count then add latest tour if (count($popular_tour) < $count) { foreach ($popular_tour as $tour) { $exclude_ids[] = ct_tour_clang_id($tour->tour_id); } $result = array_merge($result, ct_tour_get_special_tours('latest', $count - count($popular_tour), $exclude_ids, $tour_type)); } return $result; } }
function shortcode_tours($atts) { extract(shortcode_atts(array('title' => '', 'type' => 'latest', 'style' => 'advanced', 'count' => 6, 'count_per_row' => 3, 'tour_type' => '', 'post_ids' => '', 'class' => ''), $atts)); if (!ct_is_tour_enabled()) { return ''; } $styles = array('advanced', 'simple', 'list'); $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); $count = is_numeric($count) ? $count : 6; $count_per_row = is_numeric($count_per_row) ? $count_per_row : 3; $tour_type = !empty($tour_type) ? explode(',', $tour_type) : array(); 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">'; } $tours = array(); if ($type == 'selected') { $tours = ct_tour_get_tours_from_id($post_ids); } else { $tours = ct_tour_get_special_tours($type, $count, array(), $tour_type); } if ($style == 'simple') { $output = '<div class="other_tours"><ul>'; foreach ($tours as $post_obj) { $post_id = $post_obj->ID; $price = get_post_meta($post_id, '_tour_price', true); $tour_type = wp_get_post_terms($post_id, 'tour_type'); $output .= '<li><a href="' . esc_url(get_permalink($post_id)) . '">'; if (!empty($tour_type)) { $icon_class = get_tax_meta($tour_type[0]->term_id, 'ct_tax_icon_class', true); $output .= '<i class="' . esc_attr($icon_class) . '"></i>'; } $output .= get_the_title($post_id) . '<span class="other_tours_price">' . ct_price($price) . '</span></a></li>'; } $output .= '</ul></div>'; } elseif ($style == 'list') { ob_start(); if (!empty($title)) { echo '<h2>' . esc_html($title) . '</h2>'; } echo '<div class="tour-list row add-clearfix' . esc_attr($class) . '">'; foreach ($tours as $post_obj) { $post_id = $post_obj->ID; ct_get_template('loop-list.php', '/templates/tour/'); } echo '</div>'; $output = ob_get_contents(); ob_end_clean(); } else { ob_start(); if (!empty($title)) { echo '<h2>' . esc_html($title) . '</h2>'; } echo '<div class="tour-list row add-clearfix' . esc_attr($class) . '">'; foreach ($tours as $post_obj) { $post_id = $post_obj->ID; ct_get_template('loop-grid.php', '/templates/tour/'); } echo '</div>'; $output = ob_get_contents(); ob_end_clean(); } return $output; }