title: Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp
body: <p>I am trying to use jquery autocomplete to retrieve tags from <code>wordpress db</code></p>
  
  <p>First I set a function in wp:</p>
  
  <pre><code>if ( ! function_exists( 'yourtheme_frontend_scripts' ) ) {
      function yourtheme_frontend_scripts() {
  
          wp_enqueue_script( 'yourtheme_custom', get_template_directory_uri().'/js/tags.js', array( 'jquery-ui-autocomplete', 'jquery' ), '1.0.0', true );
  
          wp_localize_script( 'yourtheme_custom', 'yourtheme_autocomplete', array(
              'autocomplete' =&gt; json_encode($results_array), // Results array contains all your autocomplete words
          ) );
      }
  }
  
  add_action( 'after_setup_theme', 'yourtheme_theme_setup' );
  
  if ( ! function_exists( 'yourtheme_theme_setup' ) ) {
      function yourtheme_theme_setup() {
  
          add_action( 'wp_enqueue_scripts', 'yourtheme_frontend_scripts' );
  
      }
  }
  </code></pre>
  
  <p>Then i create a js:</p>
  
  <pre><code>$(document).ready(function($) {
      "use strict";
  
      var autocomplete_terms = JSON.parse( yourtheme_autocomplete.autocomplete );
  
      var accentMap = {
          "ä": "a",
          "ö": "o",
          "å": "a",
          "č": "c"
      };
  
      var normalize = function( term ) {
          var ret = "";
          for ( var i = 0; i &lt; term.length; i++ ) {
              ret += accentMap[ term.charAt(i) ] || term.charAt(i);
          }
          return ret;
      };
  
      $('#tags').autocomplete({
          source: function( request, response ) {
              var matcher = new RegExp( $.ui.autocomplete.escapeRegex( request.term ), "i" );
              response( $.grep( autocomplete_terms, function( value ) {
                  value = value.label || value.value || value;
                  return matcher.test( value ) || matcher.test( normalize( value ) );
              }) );
          }
      });
  
  });
  </code></pre>
  
  <p>And finally my input:</p>
  
  <pre><code>&lt;input class="form-control" id="tags"&gt;
  </code></pre>
  
  <p>But as soon as I start typing I get:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'length' of null</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>at a.(EXAMPLE PATH/anonymous function).(anonymous function).source</p>
  </blockquote>