title: MySQL select query with ajax in wordpress
body: <p>I am passing variable with ajax to list.php in my twentytwelve template. In list.php I am executing mysql select query but when I see in console I am getting this error: </p>
  
  <pre><code>&lt;br /&gt;
  &lt;b&gt;Fatal error&lt;/b&gt;:  Call to a member function get_results() on a non-object in &lt;b&gt;D:\xampp\htdocs\wordpress\wp-content\themes\twentytwelve\list.php&lt;/b&gt; on line &lt;b&gt;4&lt;/b&gt;&lt;br /&gt;
  </code></pre>
  
  <p><br><strong>My Code:</strong><br></p>
  
  <p>search.php<br></p>
  
  <pre><code>&lt;?php
  /*
  Template Name: Search
  */
  get_header();?&gt;
  
  &lt;script type="text/javascript" src="&lt;?php echo get_template_directory_uri(); ?&gt;/js/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function()
  {
    $("#parent_category").change(function()
    {
      var parent_category = $(this).val();
      if(parent_category != '')  
       {
        $.ajax
        ({
           type: "POST",
           url: "&lt;?php echo get_template_directory_uri(); ?&gt;/list.php",
           data: "parent_category="+ parent_category,
           success: function(option)
           {
             $("#child_category").html(option);
           }
        });
       }
       else
       {
         $("#child_category").html("&lt;option value=''&gt;-- No category selected --&lt;/option&gt;");
       }
      return false;
    });
  });
  &lt;/script&gt;
  
  &lt;select id="parent_category" name="parent_category"&gt;
      &lt;option value="" selected="selected"&gt;-- Select blood group --&lt;/option&gt;
      &lt;option value="A1 positive"&gt;A1 positive&lt;/option&gt;
      &lt;option value="A1 negative"&gt;A1 negative&lt;/option&gt;
      &lt;option value="A2 positive"&gt;A2 positive&lt;/option&gt;
      &lt;option value="A2 negative"&gt;A2 negative&lt;/option&gt;
      &lt;option value="B positive"&gt;B positive&lt;/option&gt;
      &lt;option value="B negative"&gt;B negative&lt;/option&gt;
      &lt;option value="A1B positive"&gt;A1B positive&lt;/option&gt;
      &lt;option value="A1B negative"&gt;A1B negative&lt;/option&gt;
      &lt;option value="A2B positive"&gt;A2B positive&lt;/option&gt;
      &lt;option value="A2B negative"&gt;A2B negative&lt;/option&gt;
      &lt;option value="AB positive"&gt;AB positive&lt;/option&gt;
      &lt;option value="AB negative"&gt;AB negative&lt;/option&gt;
      &lt;option value="O positive"&gt;O positive&lt;/option&gt;
      &lt;option value="O negative"&gt;O negative&lt;/option&gt;
      &lt;option value="A positive"&gt;A positive&lt;/option&gt;
      &lt;option value="A negative"&gt;A negative&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select id="child_category" name="child_category"&gt;
    &lt;option value=""&gt;-- No location selected --&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;?php get_footer(); ?&gt;
  </code></pre>
  
  <p><br>list.php<br></p>
  
  <pre><code>&lt;?php
  if(isset($_POST['parent_category']) &amp;&amp; $_POST['parent_category'] != '')
  {   
      $result = $wpdb-&gt;get_results( "SELECT home_location FROM wp_places WHERE blood_group LIKE '".$getGroupType."%'" );
      print_r($result);   
  }
  ?&gt;
  </code></pre>
  
  <p><br>Any ideas or suggestions? Thanks.</p>