Autocomplete or suggest from post titles inside plugin

In order to properly enqueue a script you must use the wp_enqueue_script like this :

wp_enqueue_script( 'suggest', get_template_directory_uri() . '/js/path/to/suggest.js', array('jquery'), '1.0.0', true );

The second parameter is the path to your JavaScript file, the third parameter is the dependencies the script relies on (since suggest is a jquery plugin, it must be loaded after jquery).

If you are using this, I’m afraid your call to the suggest plugin is done wrong. You whould fetch the terms first.

I personnally recommend you to use jquery ui autocomplete. I implemented it this way :

function my_autocomplete()
{
  $query = new WP_Query(array('post_type'=>'page','posts_per_page'=>-1));
  $tab = array();
  foreach ($query->posts as $p) {
    $tab[] =array('value'=>$p->post_title,'url'=>get_the_permalink($p));
  }
  die(json_encode($tab));
}
add_action( 'wp_ajax_nopriv_my_autocomplete', 'my_autocomplete' );
add_action( 'wp_ajax_my_autocomplete', 'my_autocomplete' );

the above code is in my functions.php (since you are doing a plugin, it can be in your plugin). You can change post_type to whatever you want to query.
You also have to enqueue jquery ui, which is done this way :

wp_register_script('jqui', 'https://code.jquery.com/ui/1.11.4/jquery-ui.min.js', array('jquery')); // Conditional script(s)
wp_enqueue_script('jqui'); // Enqueue it!

Then in my footer.php I have

<script type="text/javascript">
    var ajaxUrl = "/wp-admin/admin-ajax.php";
</script>

In order to define the ajax url needed by the autocompletion. Finally, the actual javascript autocomplete code (assuming your input has the class search-input):

    var data = {
        action : 'my_autocomplete'
    }

    $.post(ajaxUrl,data,function(res){
    $( ".search-input" ).autocomplete({
      minLength: 0,
      source: function(request, response) {
                var results = $.ui.autocomplete.filter(res, request.term);

                response(results.slice(0, 10));
            }
      })
      .autocomplete( "instance" )._renderItem = function( ul, item ) {
          return $( "<li>" )
            .append( "<a href=""+item.url+"">" + item.value +"</a>" )
            .appendTo( ul );
      };
    },'JSON');

So when it loads, it fetches all your page title and provide your .search-input autocomplete with the pages url. Settings here limits the autocomplete results to 10 in order to avoid gigantic lists.

This solution might not be adapted if there is a large amount of pages.

Hope it will help you.

tech