I want to add autocompletion in a nickname search bar. I do not understand why it does not work. My code is correct ?

In my file liste.php

 global $wpdb;
    $name = $_POST['code_postal'];
    $sql = $wpdb->get_results("SELECT * FROM membres WHERE pseudo LIKE '$name%' ");

    $titles = array();
    foreach($sql as $key=> $value){
        echo $value->pseudo;
    }

    echo json_encode($titles); //encode into JSON format and output

In my global.js

$('#recherche').autocomplete({
    source: function(name, response) {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: 'wp-content/themes/ARLIANE/liste.php',
            data: 'action=get_listing_names&name='+name,
            success: function(data) {
                response(data);
            }
        });
    }
});

In my index.php

<form>
  <input type="text" name="term" id="recherche"/>
</form>

Read more here: JQuery UI Autocomplete WordPress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: