| 1 |
<?php |
| 2 |
/** |
| 3 |
* Search Shortcode Template |
| 4 |
* |
| 5 |
* @package Yatra |
| 6 |
* @var array $atts Shortcode attributes |
| 7 |
* @var array $categories Available categories |
| 8 |
* @var array $destinations Available destinations |
| 9 |
* @var array $activities Available activities |
| 10 |
* @var array $difficulties Available difficulty levels |
| 11 |
*/ |
| 12 |
|
| 13 |
// Prevent direct access |
| 14 |
if (!defined('ABSPATH')) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
?> |
| 18 |
|
| 19 |
<div class="yatra-search-shortcode"> |
| 20 |
<form class="yatra-search-form" method="get" action="<?php echo esc_url(get_post_type_archive_link('trip')); ?>"> |
| 21 |
<div class="yatra-search-main"> |
| 22 |
<div class="yatra-search-input-group"> |
| 23 |
<?php echo yatra_svg_icon('search', 'yatra-search-icon'); ?> |
| 24 |
<input |
| 25 |
type="text" |
| 26 |
name="s" |
| 27 |
class="yatra-search-input" |
| 28 |
placeholder="<?php echo esc_attr($atts['placeholder']); ?>" |
| 29 |
value="<?php echo esc_attr(isset($_GET['s']) ? sanitize_text_field(wp_unslash($_GET['s'])) : ''); ?>" |
| 30 |
> |
| 31 |
<button type="submit" class="yatra-search-btn"> |
| 32 |
<?php echo esc_html($atts['button_text']); ?> |
| 33 |
</button> |
| 34 |
</div> |
| 35 |
</div> |
| 36 |
|
| 37 |
<?php if ($atts['show_filters'] === 'yes'): ?> |
| 38 |
<div class="yatra-search-filters"> |
| 39 |
<div class="yatra-filters-toggle"> |
| 40 |
<button type="button" class="yatra-filters-toggle-btn"> |
| 41 |
<?php echo yatra_svg_icon('filter', 'yatra-filter-icon'); ?> |
| 42 |
<?php esc_html_e('Advanced Filters', 'yatra'); ?> |
| 43 |
<?php echo yatra_svg_icon('chevron-down', 'yatra-chevron-icon'); ?> |
| 44 |
</button> |
| 45 |
</div> |
| 46 |
|
| 47 |
<div class="yatra-filters-content"> |
| 48 |
<div class="yatra-filters-grid"> |
| 49 |
<?php if ($atts['show_categories'] === 'yes' && !empty($categories)): ?> |
| 50 |
<div class="yatra-filter-group"> |
| 51 |
<label for="yatra-search-category"><?php esc_html_e('Category', 'yatra'); ?></label> |
| 52 |
<select id="yatra-search-category" name="category" class="yatra-filter-select"> |
| 53 |
<option value=""><?php esc_html_e('All Categories', 'yatra'); ?></option> |
| 54 |
<?php foreach ($categories as $category): ?> |
| 55 |
<option value="<?php echo esc_attr($category->slug); ?>" <?php selected(isset($_GET['category']) ? sanitize_text_field(wp_unslash($_GET['category'])) : '', $category->slug); ?>> |
| 56 |
<?php echo esc_html($category->name); ?> |
| 57 |
</option> |
| 58 |
<?php endforeach; ?> |
| 59 |
</select> |
| 60 |
</div> |
| 61 |
<?php endif; ?> |
| 62 |
|
| 63 |
<?php if ($atts['show_destinations'] === 'yes' && !empty($destinations)): ?> |
| 64 |
<div class="yatra-filter-group"> |
| 65 |
<label for="yatra-search-destination"><?php esc_html_e('Destination', 'yatra'); ?></label> |
| 66 |
<select id="yatra-search-destination" name="destination" class="yatra-filter-select"> |
| 67 |
<option value=""><?php esc_html_e('All Destinations', 'yatra'); ?></option> |
| 68 |
<?php foreach ($destinations as $destination): ?> |
| 69 |
<option value="<?php echo esc_attr($destination->slug); ?>" <?php selected(isset($_GET['destination']) ? sanitize_text_field(wp_unslash($_GET['destination'])) : '', $destination->slug); ?>> |
| 70 |
<?php echo esc_html($destination->name); ?> |
| 71 |
</option> |
| 72 |
<?php endforeach; ?> |
| 73 |
</select> |
| 74 |
</div> |
| 75 |
<?php endif; ?> |
| 76 |
|
| 77 |
<?php if ($atts['show_activities'] === 'yes' && !empty($activities)): ?> |
| 78 |
<div class="yatra-filter-group"> |
| 79 |
<label for="yatra-search-activity"><?php esc_html_e('Activity', 'yatra'); ?></label> |
| 80 |
<select id="yatra-search-activity" name="activity" class="yatra-filter-select"> |
| 81 |
<option value=""><?php esc_html_e('All Activities', 'yatra'); ?></option> |
| 82 |
<?php foreach ($activities as $activity): ?> |
| 83 |
<option value="<?php echo esc_attr($activity->slug); ?>" <?php selected(isset($_GET['activity']) ? sanitize_text_field(wp_unslash($_GET['activity'])) : '', $activity->slug); ?>> |
| 84 |
<?php echo esc_html($activity->name); ?> |
| 85 |
</option> |
| 86 |
<?php endforeach; ?> |
| 87 |
</select> |
| 88 |
</div> |
| 89 |
<?php endif; ?> |
| 90 |
|
| 91 |
<?php if ($atts['show_difficulty'] === 'yes' && !empty($difficulties)): ?> |
| 92 |
<div class="yatra-filter-group"> |
| 93 |
<label for="yatra-search-difficulty"><?php esc_html_e('Difficulty', 'yatra'); ?></label> |
| 94 |
<select id="yatra-search-difficulty" name="difficulty" class="yatra-filter-select"> |
| 95 |
<option value=""><?php esc_html_e('All Levels', 'yatra'); ?></option> |
| 96 |
<?php foreach ($difficulties as $difficulty): ?> |
| 97 |
<option value="<?php echo esc_attr($difficulty->slug); ?>" <?php selected(isset($_GET['difficulty']) ? sanitize_text_field(wp_unslash($_GET['difficulty'])) : '', $difficulty->slug); ?>> |
| 98 |
<?php echo esc_html($difficulty->name); ?> |
| 99 |
</option> |
| 100 |
<?php endforeach; ?> |
| 101 |
</select> |
| 102 |
</div> |
| 103 |
<?php endif; ?> |
| 104 |
|
| 105 |
<?php if ($atts['show_price_range'] === 'yes'): ?> |
| 106 |
<div class="yatra-filter-group yatra-filter-group-full"> |
| 107 |
<label><?php esc_html_e('Price Range', 'yatra'); ?></label> |
| 108 |
<div class="yatra-price-range"> |
| 109 |
<input |
| 110 |
type="number" |
| 111 |
name="price_min" |
| 112 |
class="yatra-price-input" |
| 113 |
placeholder="<?php esc_attr_e('Min', 'yatra'); ?>" |
| 114 |
value="<?php echo esc_attr(isset($_GET['price_min']) ? sanitize_text_field(wp_unslash((string) $_GET['price_min'])) : ''); ?>" |
| 115 |
min="0" |
| 116 |
> |
| 117 |
<span class="yatra-price-separator">-</span> |
| 118 |
<input |
| 119 |
type="number" |
| 120 |
name="price_max" |
| 121 |
class="yatra-price-input" |
| 122 |
placeholder="<?php esc_attr_e('Max', 'yatra'); ?>" |
| 123 |
value="<?php echo esc_attr(isset($_GET['price_max']) ? sanitize_text_field(wp_unslash((string) $_GET['price_max'])) : ''); ?>" |
| 124 |
min="0" |
| 125 |
> |
| 126 |
</div> |
| 127 |
</div> |
| 128 |
<?php endif; ?> |
| 129 |
|
| 130 |
<?php if ($atts['show_duration'] === 'yes'): ?> |
| 131 |
<div class="yatra-filter-group"> |
| 132 |
<label for="yatra-search-duration"><?php esc_html_e('Duration', 'yatra'); ?></label> |
| 133 |
<select id="yatra-search-duration" name="duration" class="yatra-filter-select"> |
| 134 |
<option value=""><?php esc_html_e('Any Duration', 'yatra'); ?></option> |
| 135 |
<option value="1-3" <?php selected(isset($_GET['duration']) ? sanitize_text_field(wp_unslash($_GET['duration'])) : '', '1-3'); ?>>1-3 <?php esc_html_e('days', 'yatra'); ?></option> |
| 136 |
<option value="4-7" <?php selected(isset($_GET['duration']) ? sanitize_text_field(wp_unslash($_GET['duration'])) : '', '4-7'); ?>>4-7 <?php esc_html_e('days', 'yatra'); ?></option> |
| 137 |
<option value="8-14" <?php selected(isset($_GET['duration']) ? sanitize_text_field(wp_unslash($_GET['duration'])) : '', '8-14'); ?>>8-14 <?php esc_html_e('days', 'yatra'); ?></option> |
| 138 |
<option value="15+" <?php selected(isset($_GET['duration']) ? sanitize_text_field(wp_unslash($_GET['duration'])) : '', '15+'); ?>>15+ <?php esc_html_e('days', 'yatra'); ?></option> |
| 139 |
</select> |
| 140 |
</div> |
| 141 |
<?php endif; ?> |
| 142 |
</div> |
| 143 |
|
| 144 |
<div class="yatra-filters-actions"> |
| 145 |
<button type="submit" class="yatra-btn yatra-btn-primary"> |
| 146 |
<?php esc_html_e('Apply Filters', 'yatra'); ?> |
| 147 |
</button> |
| 148 |
<button type="button" class="yatra-btn yatra-btn-outline yatra-reset-filters"> |
| 149 |
<?php esc_html_e('Reset', 'yatra'); ?> |
| 150 |
</button> |
| 151 |
</div> |
| 152 |
</div> |
| 153 |
</div> |
| 154 |
<?php endif; ?> |
| 155 |
</form> |
| 156 |
</div> |
| 157 |
|
| 158 |
<style> |
| 159 |
.yatra-search-shortcode { |
| 160 |
margin: 30px 0; |
| 161 |
} |
| 162 |
|
| 163 |
.yatra-search-form { |
| 164 |
background: white; |
| 165 |
border: 1px solid #e5e7eb; |
| 166 |
border-radius: 12px; |
| 167 |
overflow: hidden; |
| 168 |
} |
| 169 |
|
| 170 |
.yatra-search-main { |
| 171 |
padding: 20px; |
| 172 |
} |
| 173 |
|
| 174 |
.yatra-search-input-group { |
| 175 |
display: flex; |
| 176 |
align-items: center; |
| 177 |
gap: 15px; |
| 178 |
background: #f9fafb; |
| 179 |
border: 1px solid #e5e7eb; |
| 180 |
border-radius: 8px; |
| 181 |
padding: 5px; |
| 182 |
transition: border-color 0.3s ease; |
| 183 |
} |
| 184 |
|
| 185 |
.yatra-search-input-group:focus-within { |
| 186 |
border-color: #3b82f6; |
| 187 |
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); |
| 188 |
} |
| 189 |
|
| 190 |
.yatra-search-icon { |
| 191 |
width: 20px; |
| 192 |
height: 20px; |
| 193 |
color: #6b7280; |
| 194 |
margin-left: 10px; |
| 195 |
} |
| 196 |
|
| 197 |
.yatra-search-input { |
| 198 |
flex: 1; |
| 199 |
border: none; |
| 200 |
background: transparent; |
| 201 |
padding: 10px 5px; |
| 202 |
font-size: 1rem; |
| 203 |
outline: none; |
| 204 |
} |
| 205 |
|
| 206 |
.yatra-search-input::placeholder { |
| 207 |
color: #9ca3af; |
| 208 |
} |
| 209 |
|
| 210 |
.yatra-search-btn { |
| 211 |
background: #3b82f6; |
| 212 |
color: white; |
| 213 |
border: none; |
| 214 |
padding: 10px 20px; |
| 215 |
border-radius: 6px; |
| 216 |
font-weight: 500; |
| 217 |
cursor: pointer; |
| 218 |
transition: background-color 0.3s ease; |
| 219 |
} |
| 220 |
|
| 221 |
.yatra-search-btn:hover { |
| 222 |
background: #2563eb; |
| 223 |
} |
| 224 |
|
| 225 |
.yatra-search-filters { |
| 226 |
border-top: 1px solid #e5e7eb; |
| 227 |
} |
| 228 |
|
| 229 |
.yatra-filters-toggle { |
| 230 |
padding: 15px 20px; |
| 231 |
background: #f9fafb; |
| 232 |
border-bottom: 1px solid #e5e7eb; |
| 233 |
} |
| 234 |
|
| 235 |
.yatra-filters-toggle-btn { |
| 236 |
display: flex; |
| 237 |
align-items: center; |
| 238 |
gap: 10px; |
| 239 |
background: none; |
| 240 |
border: none; |
| 241 |
padding: 8px 16px; |
| 242 |
border-radius: 6px; |
| 243 |
cursor: pointer; |
| 244 |
color: #6b7280; |
| 245 |
font-weight: 500; |
| 246 |
transition: all 0.3s ease; |
| 247 |
width: 100%; |
| 248 |
justify-content: center; |
| 249 |
} |
| 250 |
|
| 251 |
.yatra-filters-toggle-btn:hover { |
| 252 |
background: #e5e7eb; |
| 253 |
color: #374151; |
| 254 |
} |
| 255 |
|
| 256 |
.yatra-filter-icon { |
| 257 |
width: 16px; |
| 258 |
height: 16px; |
| 259 |
} |
| 260 |
|
| 261 |
.yatra-chevron-icon { |
| 262 |
width: 16px; |
| 263 |
height: 16px; |
| 264 |
transition: transform 0.3s ease; |
| 265 |
} |
| 266 |
|
| 267 |
.yatra-filters-toggle-btn.yatra-filters-open .yatra-chevron-icon { |
| 268 |
transform: rotate(180deg); |
| 269 |
} |
| 270 |
|
| 271 |
.yatra-filters-content { |
| 272 |
display: none; |
| 273 |
padding: 20px; |
| 274 |
} |
| 275 |
|
| 276 |
.yatra-filters-content.yatra-filters-open { |
| 277 |
display: block; |
| 278 |
} |
| 279 |
|
| 280 |
.yatra-filters-grid { |
| 281 |
display: grid; |
| 282 |
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); |
| 283 |
gap: 20px; |
| 284 |
margin-bottom: 20px; |
| 285 |
} |
| 286 |
|
| 287 |
.yatra-filter-group { |
| 288 |
display: flex; |
| 289 |
flex-direction: column; |
| 290 |
} |
| 291 |
|
| 292 |
.yatra-filter-group-full { |
| 293 |
grid-column: 1 / -1; |
| 294 |
} |
| 295 |
|
| 296 |
.yatra-filter-group label { |
| 297 |
margin-bottom: 8px; |
| 298 |
font-weight: 500; |
| 299 |
color: #374151; |
| 300 |
font-size: 0.875rem; |
| 301 |
} |
| 302 |
|
| 303 |
.yatra-filter-select, |
| 304 |
.yatra-price-input { |
| 305 |
padding: 10px 12px; |
| 306 |
border: 1px solid #d1d5db; |
| 307 |
border-radius: 6px; |
| 308 |
font-size: 0.875rem; |
| 309 |
background: white; |
| 310 |
} |
| 311 |
|
| 312 |
.yatra-filter-select:focus, |
| 313 |
.yatra-price-input:focus { |
| 314 |
outline: none; |
| 315 |
border-color: #3b82f6; |
| 316 |
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); |
| 317 |
} |
| 318 |
|
| 319 |
.yatra-price-range { |
| 320 |
display: flex; |
| 321 |
align-items: center; |
| 322 |
gap: 10px; |
| 323 |
} |
| 324 |
|
| 325 |
.yatra-price-input { |
| 326 |
flex: 1; |
| 327 |
} |
| 328 |
|
| 329 |
.yatra-price-separator { |
| 330 |
color: #6b7280; |
| 331 |
font-weight: 500; |
| 332 |
} |
| 333 |
|
| 334 |
.yatra-filters-actions { |
| 335 |
display: flex; |
| 336 |
gap: 10px; |
| 337 |
justify-content: center; |
| 338 |
padding-top: 20px; |
| 339 |
border-top: 1px solid #f3f4f6; |
| 340 |
} |
| 341 |
|
| 342 |
/* Responsive Design */ |
| 343 |
@media (max-width: 768px) { |
| 344 |
.yatra-search-input-group { |
| 345 |
flex-direction: column; |
| 346 |
gap: 10px; |
| 347 |
} |
| 348 |
|
| 349 |
.yatra-search-icon { |
| 350 |
margin-left: 0; |
| 351 |
align-self: center; |
| 352 |
} |
| 353 |
|
| 354 |
.yatra-search-btn { |
| 355 |
width: 100%; |
| 356 |
} |
| 357 |
|
| 358 |
.yatra-filters-grid { |
| 359 |
grid-template-columns: 1fr; |
| 360 |
} |
| 361 |
|
| 362 |
.yatra-price-range { |
| 363 |
flex-direction: column; |
| 364 |
align-items: stretch; |
| 365 |
} |
| 366 |
|
| 367 |
.yatra-price-separator { |
| 368 |
text-align: center; |
| 369 |
} |
| 370 |
|
| 371 |
.yatra-filters-actions { |
| 372 |
flex-direction: column; |
| 373 |
} |
| 374 |
} |
| 375 |
</style> |
| 376 |
|
| 377 |
<script> |
| 378 |
document.addEventListener('DOMContentLoaded', function() { |
| 379 |
// Filter toggle functionality |
| 380 |
const toggleBtn = document.querySelector('.yatra-filters-toggle-btn'); |
| 381 |
const filtersContent = document.querySelector('.yatra-filters-content'); |
| 382 |
|
| 383 |
if (toggleBtn && filtersContent) { |
| 384 |
toggleBtn.addEventListener('click', function() { |
| 385 |
this.classList.toggle('yatra-filters-open'); |
| 386 |
filtersContent.classList.toggle('yatra-filters-open'); |
| 387 |
}); |
| 388 |
} |
| 389 |
|
| 390 |
// Reset filters functionality |
| 391 |
const resetBtn = document.querySelector('.yatra-reset-filters'); |
| 392 |
if (resetBtn) { |
| 393 |
resetBtn.addEventListener('click', function() { |
| 394 |
const form = document.querySelector('.yatra-search-form'); |
| 395 |
if (form) { |
| 396 |
// Reset all select elements |
| 397 |
form.querySelectorAll('select').forEach(select => { |
| 398 |
select.selectedIndex = 0; |
| 399 |
}); |
| 400 |
|
| 401 |
// Reset all input fields except search |
| 402 |
form.querySelectorAll('input[type="number"]').forEach(input => { |
| 403 |
input.value = ''; |
| 404 |
}); |
| 405 |
|
| 406 |
// Keep search term if it exists |
| 407 |
const searchInput = form.querySelector('input[name="s"]'); |
| 408 |
if (searchInput && !searchInput.value) { |
| 409 |
form.submit(); |
| 410 |
} |
| 411 |
} |
| 412 |
}); |
| 413 |
} |
| 414 |
}); |
| 415 |
</script> |
| 416 |
|