jquery auto complete in wordpress

I am trying to use jquery auto complete in word-press search.

However, though I get a result via ajax, I couldn’t jquery-UI auto complete work.

Read More

here is my jquery code.

$("#searchbox").keyup(function(e){
        e.preventDefault();
        var search_val=$("#searchbox").val(); 
        $.ajax({
            type:"POST",
            url: "./wp-admin/admin-ajax.php",
            data: {
                action:'wpay_search', 
                user_name:search_val
            },
            success:function(data){

                //$('#search_result').html(data);
                $( "#searchbox" ).autocomplete({
                source: data
                });

            }
        }); 


});

here is my php code

function wpay_search() {

    global $wpdb;
    $name=$_POST['user_name'];
    echo $name;
    $employee=$wpdb->get_results("SELECT `First_Name`, last_name FROM users WHERE First_name LIKE '$name%' ");

    foreach($employee as $key=> $value){
    echo $value->First_Name;
    }

    //wp_reset_query();
    die();
} // end theme_custom_handler
add_action( 'wp_ajax_wpay_search', 'wpay_search' );
add_action( 'wp_ajax_nopriv_wpay_search', 'wpay_search' );

How to implement auto completer in wordpress? Where I have missed?

Related posts

Leave a Reply

1 comment