File: /var/www/vhosts/greenclinic.kz/newsite/wp-content/themes/green-clinic/template-parts/search.php
<section class="section main-custom-search-section">
<div class="container">
<div class="search__container">
<h2>
<?php
// Get the current language
$current_language = wpm_get_language();
// Output the appropriate translation based on the current language
if ($current_language == 'en') {
echo 'Directions and services';
} elseif ($current_language == 'kz') {
echo 'Бағыттар мен қызметтер';
} else {
echo 'Направление и услуги'; // Default to Russian or the original language
}
?>
</h2>
<div class="search__input">
<div>
<svg
width="26"
height="24"
viewBox="0 0 26 24"
fill="none"
xmlns="http://www.w3.org/2000/svg">
<ellipse
cx="11.6757"
cy="11"
rx="6.32411"
ry="6"
stroke="#004C2E" />
<path
d="M21.1611 20L17.999 17"
stroke="#004C2E"
stroke-linecap="round" />
</svg>
</div>
<input id="searchInput" type="text"
placeholder="<?php
// Get the current language
//$current_language = wpm_get_language();
// Output the appropriate translation based on the current language
if ($current_language == 'en') {
echo 'Search...';
} elseif ($current_language == 'kz') {
echo 'Іздеу...';
} else {
echo 'Найти...'; // Default to Russian or the original language
}
?>" />
<div class="yellow-button" id="searchBtn" style="cursor:pointer; margin-top: 0 !important;line-height: 1;"><br>
<span class="yellow-button-label" style=" padding: 25px;"><?php
// Get the current language
//$current_language = wpm_get_language();
// Output the appropriate translation based on the current language
if ($current_language == 'en') {
echo 'Search';
} elseif ($current_language == 'kz') {
echo 'Іздеу';
} else {
echo 'Поиск'; // Default to Russian or the original language
}
?></span><br>
<img decoding="async" src="/wp-content/uploads/arrow-readmore.svg"><br>
</div>
</div>
<div class="preloader" style="display: none;"><img src="/wp-content/plugins/ajax-directions/load.gif" class="loader" /></div>
<?php
/*global $wpdb;
$searchItem = 'мрт';
$results = $wpdb->get_results("SELECT * FROM {$wpdb->postmeta} WHERE meta_value REGEXP '
' AND meta_key REGEXP 'prices_'", OBJECT);*/
/*
--------------
$itemArray = [];
$k = 0;
$i = 0;
$serVal = 'лазер';
$serValUp = mb_strtoupper($serVal);
$serValLow = mb_strtolower($serVal);
$serValArray = [$serVal, $serValUp, $serValLow];
//echo $serVal;
//echo $serValUp;
//echo $serValLow;
$args = array(
'post_type' => 'prices',
'meta_query' => array(
'relation' => 'AND',
array(
'value' => $serVal,
'compare' => 'LIKE'
)
)
);
$query = new WP_Query($args);
$cusResult = $query->posts;
$test = $query->query_vars['s'];
$search = get_query_var('s');
//var_dump($search);
foreach ($cusResult as $cusResultItem) {
$post_id = $cusResultItem->ID;
$prices = get_field('prices', $post_id);
$k = 0;
foreach ($prices as $prices_item) {
$name = mb_strtolower($prices_item['name']);
$search = mb_strtolower($serVal);
//echo $name .' '. $search;
if (strpos($name, $search)) {
if ($k === 0) {
$postTitle = get_the_title($post_id);
$itemArray[$post_id][$k] = [
'id' => $post_id,
'pricename' => $postTitle,
'nomer' => $prices_item['nomer'],
'name' => $prices_item['name'],
'price' => $prices_item['price'],
'count' => $prices_item['count'],
];
} else {
$itemArray[$post_id][$k] = [
'id' => $post_id,
'nomer' => $prices_item['nomer'],
'name' => $prices_item['name'],
'price' => $prices_item['price'],
'count' => $prices_item['count'],
];
}
$k++;
}
}
}
*/
?>
</div>
<div class="search__results-container" id="search__results-container">
<div class="search__filters mt-60">
<div class="search__filter filter-one pointer chosen" id="osmsFilter">
<span><?php
// Get the current language
//$current_language = wpm_get_language();
// Output the appropriate translation based on the current language
if ($current_language == 'ru') {
echo 'Поликлиника ОСМС';
} elseif ($current_language == 'kz') {
echo 'МӘМС емханасы';
} else {
echo 'OSMS Polyclinic'; // Default to Russian or the original language
}
?></span>
</div>
<div class="search__filter pointer" id="paidFilter">
<span>
<?php
// Get the current language
//$current_language = wpm_get_language();
// Output the appropriate translation based on the current language
if ($current_language == 'ru') {
echo 'Поликлиника платная';
} elseif ($current_language == 'kz') {
echo 'Емхана ақылы';
} else {
echo 'The clinic is paid'; // Default to Russian or the original language
}
?>
</span>
</div>
</div>
<div class="search__results open" id="search__results">
</div>
<div class="search__results" id="search__results_paid">
</div>
<div class="search__results" id="search__results_osms">
</div>
</div>
<!------------->
<?php
$biznes = new WP_Query(array(
'order' => 'ASC',
'orderby' => 'date', // тип сортировки (в данном случае по дате)
'post_type' => 'prices',
'posts_per_page' => -1
));
?>
<div class="services-container">
<div class="service-group accordion">
<?php $i = 1; ?>
<?php while ($biznes->have_posts()) {
$biznes->the_post(); ?>
<div class="service-group-title">
<div class="service-group-title-left ">
<p><?php echo $i; ?>.</p>
<p> <a href="<?php echo get_permalink(); ?>" class="biznes__item--linck" style="color: black !important;"><?php the_title(); ?></a> </p>
</div>
</div>
<?php $i++; ?>
<?php } ?>
</div>
</div>
<style>
.service-group-title {
margin-top: 45px;
}
.ui-accordion-header-icon {
display: none;
}
.service-group:first-of-type .service-group-list {
max-height: 100%;
}
</style>
<script src="https://snipp.ru/cdn/jquery/2.1.1/jquery.min.js"></script>
<script src="https://snipp.ru/cdn/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
$('.accordion').accordion({
heightStyle: 'content',
header: '.accordion-header'
});
</script>
<!-------------------->
</div>
</div>
</section>
<script>
// Debounce function to limit the rate of invoking the performSearch function
function debounce(func, wait, immediate) {
let timeout;
return function() {
const context = this,
args = arguments;
const later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
// Function to perform the search via AJAX
function performSearch() {
let searchTerm = jQuery('#searchInput').val().trim();
// Only perform the search if the search term is not too short
if (searchTerm.length < 3) {
// Optionally, clear the search results if the term is too short
jQuery('#search__results').html('');
return;
}
// Show the preloader animation
jQuery('.preloader').show();
// Send the AJAX request to perform the search
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'POST',
data: {
action: 'search_prices',
term: searchTerm
},
success: function(response) {
// Display the search results
jQuery('#search__results').html(response);
// Hide the preloader animation
jQuery('.preloader').hide();
},
error: function() {
// Hide the preloader animation
jQuery('.preloader').hide();
// Display an error message to the user
alert('Search failed. Please try again.');
}
});
}
(function($) {
$(document).ready(function() {
// Debounce the keyup event to limit the rate of AJAX requests
const debouncedSearch = debounce(performSearch, 300);
// Attach the debounced search function to the keyup event on the search input
$('#searchBtn').on('click', debouncedSearch);
var value_two = localStorage.getItem("value_ls");
var click_two = localStorage.getItem("value_click");
if (click_two == 1) {
let serIn = $('#searchInput');
serIn.val(value_two);
serIn.trigger('keydown');
serIn.trigger('keyup');
localStorage.removeItem("value_ls");
localStorage.removeItem("value_click");
localStorage.clear();
} else {}
$('#paidFilter').on('click', function() {
$('#search__results').removeClass('open');
$('#search__results_osms').removeClass('open');
$('#search__results_paid').addClass('open');
});
$('#osmsFilter').on('click', function() {
$('#search__results').removeClass('open');
$('#search__results_paid').removeClass('open');
$('#search__results_osms').addClass('open');
});
});
$('body').on('click', '.search__results-service', function() {
var value_name = $(this).find('.search__service-name').html();
var value_price = $(this).find('.search__results-price').html();
var value_type = $(this).find('.search__service-type').html();
var value_price_id = $(this).find('#pageidid').html();
var click_one = 1;
localStorage.setItem("value_name", value_name);
localStorage.setItem("value_price", value_price);
localStorage.setItem("value_type", value_type);
localStorage.setItem("value_click", click_one);
localStorage.setItem("value_price_id", value_price_id);
console.log(value_price_id);
document.location.href = '/zapis-na-priem';
});
})(jQuery);
</script>
<style>
.search__container {
position: relative;
}
.preloader {
position: fixed;
top: 50%;
right: 50%;
transform: translate(-50%, -50%);
z-index: 6;
}
.preloader img {
width: 30px;
height: 30px;
}
</style>