title: Jquery Autocomplete source within same file
body: <p>I'm trying to implement this script within Wordpress (<a href="http://af-design.com/blog/2010/05/12/using-jquery-uis-autocomplete-to-populate-a-form/" rel="nofollow">http://af-design.com/blog/2010/05/12/using-jquery-uis-autocomplete-to-populate-a-form/</a>) getting the Array from Wordpress database. The issue is that <strong>Wordpress database connect $wpdb</strong> won't work calling an external php like <strong>demo_cities.php</strong></p>
  
  <p>Can you tell me what the source would be if I integrate the <strong>demo_cities.php</strong> into the HTML? Is this even possible?</p>
  
  <p>Can I create the array in Wordpress page and just call the rest of the script as it is?</p>
  
  <p>Thanks</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
      var ac_config = {
          source: "/ajax/demo_cities.php",
          select: function(event, ui){
              $("#city").val(ui.item.city);
              $("#state").val(ui.item.state);
              $("#zip").val(ui.item.zip);
          },
          minLength:1
      };
      $("#city").autocomplete(ac_config);
  });
  &lt;/script&gt;
  &lt;form action="#" method="post"&gt;
       &lt;p&gt;&lt;label for="city"&gt;City&lt;/label&gt;&lt;br /&gt;
           &lt;input type="text" name="city" id="city" value="" /&gt;&lt;/p&gt;
       &lt;p&gt;&lt;label for="state"&gt;State&lt;/label&gt;&lt;br /&gt;
           &lt;input type="text" name="state" id="state" value="" /&gt;&lt;/p&gt;
       &lt;p&gt;&lt;label for="zip"&gt;Zip&lt;/label&gt;&lt;br /&gt;
           &lt;input type="text" name="zip" id="zip" value="" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>demo_cities.php</strong></p>
  
  <pre><code>&lt;?php
  
  // Data could be pulled from a DB or other source
  $cities = array(
      array('city'=&gt;'New York', state=&gt;'NY', zip=&gt;'10001'),
      array('city'=&gt;'Los Angeles', state=&gt;'CA', zip=&gt;'90001'),
      array('city'=&gt;'Chicago', state=&gt;'IL', zip=&gt;'60601'),
      array('city'=&gt;'Houston', state=&gt;'TX', zip=&gt;'77001'),
      array('city'=&gt;'Phoenix', state=&gt;'AZ', zip=&gt;'85001'),
      array('city'=&gt;'Philadelphia', state=&gt;'PA', zip=&gt;'19019'),
  );
  
  // Cleaning up the term
  $term = trim(strip_tags($_GET['term']));
  
  // Rudimentary search
  $matches = array();
  foreach($cities as $city){
      if(stripos($city['city'], $term) !== false){
          // Add the necessary "value" and "label" fields and append to result set
          $city['value'] = $city['city'];
          $city['label'] = "{$city['city']}, {$city['state']} {$city['zip']}";
          $matches[] = $city;
      }
  }
  
  // Truncate, encode and return the results
  $matches = array_slice($matches, 0, 5);
  print json_encode($matches);
  
  ?&gt;
  </code></pre>