Scroll to top

How to use search ajax in wordpress?

Notice: Undefined variable: string in /home/u665484253/domains/ on line 61

search ajax in wordpress

Use in html file 


.sec {
width: 223px;
height: 41px;
border: 1px solid #54595f;
<script src=”<?php echo plugin_dir_url(__FILE__);?>js/jquery.min.js” type=”text/javascript”></script>
$(“.filter”).bind(“keyup change”, function() {

var ajaxurl = $(“.ajaxurl”).val();
var bylocation = $(“#by-search”).val();

var data = {
‘action’: ‘showloactions’,
‘bylocation’: bylocation,
};, data, function(response) {

<form action=”” method=”post”>
<input type=”text” name=”search” class=”filter” id=”by-search”>
<input type=”hidden” class=”ajaxurl” value=”<?php echo admin_url( ‘admin-ajax.php’ ) ;?>”>

<div class=”wrapper”>




Use in main plugin file 

function showloactions(){

$bylocation = $_POST[‘bylocation’];
if(!$bylocation == “”){
global $wpdb;
global $wpsite;
$lacationtable = $wpdb->prefix.$wpsite.”_locations”;
$result = $wpdb->get_results ( “SELECT * FROM $lacationtable where address LIKE ‘%$bylocation%'” );
foreach ( $result as $print )   {

<div class=”sec”><?php echo $print->city; ?></div>

echo “Not Found”;



add_action(‘wp_ajax_showloactions’, ‘showloactions’);
add_action(‘wp_ajax_nopriv_showloactions’, ‘showloactions’);


Get more information


Read More Posts

Leave a Reply

Your email address will not be published.