title: Ajax request to query_posts is undefined
body: <p>I'm trying to implement an Ajax request to load more posts on click.</p>
  
  <p>However I've got an error : <code>Call to undefined function query_posts()</code>  </p>
  
  <p>Here is my Ajax script : </p>
  
  <pre><code>$('#next-container').click(function() { 
      var IDs = [];
      $(".element").each(function(){ IDs.push(this.id); });
  
      $('#next-container').html('loading');
  
      $.ajax({
          url: 'wp-content/themes/freakyshape/inc/data.php',
          type: 'POST',
          data: {'post_ids[]': IDs },
          success: function(data) {
              $container.isotope( 'insert', $(data));
          }
      });
  });
  </code></pre>
  
  <p>my data.php file to load post:</p>
  
  <pre><code>&lt;?php
  if (isset($_POST['post_ids'])) {
  
  $ids = array(); 
  $ids[] = $_POST['post_ids'];
  
  $posts_per_page = 8;
  
  global $wp_query;
  query_posts(array('post_type' =&gt; array('post', 'portfolio'), 'post__not_in' =&gt; $ids, 'posts_per_page' =&gt; $posts_per_page));
  while (have_posts()) : the_post();  
  ?&gt;
  
  // I do some stuff echo;
  
  &lt;?php
  endwhile;
  wp_reset_query();
  }
  ?&gt;
  </code></pre>
  
  <p>and in my functions.php:</p>
  
  <pre><code>$admin_path = TEMPLATEPATH . "/inc/";
  require_once ($admin_path . "data.php");
  </code></pre>
  
  <p>What do I need to make it work?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I try with the right way to do it but nothing works like this... I miss something... It's not easy to correctly understand blog instruction when you are not fluent in English...</p>
  
  <p>function.php:</p>
  
  <pre><code>add_action('wp_ajax_load_post', 'load_post_callback');
  add_action('wp_ajax_nopriv_load_post', 'load_post_callback');
  wp_enqueue_script('script', get_template_directory_uri().'/js/load_post.js', array('jquery'), '1.0', 1 );
  wp_localize_script('script', 'ajax_var', array('url' =&gt; admin_url('admin-ajax.php'), 'nonce' =&gt; wp_create_nonce('ajax-nonce')));
  </code></pre>
  
  <p>load_post.php :</p>
  
  <pre><code>&lt;?php
  
  function load_post_callback() {
  
  if (isset($_POST['post_ids'])) {
  
      $nonce = $_POST['nonce'];
  
      if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) ) {
          die ( 'Interdit !');
      }
  
      $ids = array(); 
      $ids[] = $_POST['post_ids'];
  
      $posts_per_page = 8;
      global $wp_query;
      query_posts(array('post_type' =&gt; array('post', 'portfolio'), 'post__not_in' =&gt; $ids, 'posts_per_page' =&gt; $posts_per_page));
      while (have_posts()) : the_post();
  
      $post_type = get_post_type( $post-&gt;ID );
      if ($post_type == 'post') {
          $post_type = 'blog';
      }
  ?&gt;
  
  &lt;div class="element normal &lt;?php echo $post_type; ?&gt;" id="&lt;?php echo the_id(); ?&gt;"&gt;
      &lt;div class="element-container"&gt;
          &lt;img  src="&lt;?php echo  wp_get_attachment_url( get_post_thumbnail_id()); ?&gt;" class="thumbnail" /&gt;
          &lt;div class="element-back"&gt;&lt;/div&gt;
          &lt;div class="element-description"&gt;&lt;?php echo the_title(); ?&gt;&lt;/div&gt;
          &lt;div class="element-category"&gt;&lt;i class="icon"&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp &lt;?php echo $post_type; ?&gt;&lt;/div&gt;
          &lt;a class="link" href="" title="&lt;?php echo the_title(); ?&gt;" onclick="gestionClic(compteur'id');"&gt;
              &lt;div class="more"&gt;more.&lt;/div&gt;
          &lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;  
  
  &lt;?php
      endwhile;
      wp_reset_query();
      }
  }
  ?&gt;
  </code></pre>
  
  <p>load_post.js:</p>
  
  <pre><code>jQuery(document).ready(function() { 
  
      var url = ajax_var.url;
      var nonce = ajax_var.nonce;
  
      jQuery('#next-container').click(function() { 
  
              var IDs = [];
              $(".element").each(function(){ IDs.push(this.id); });
              console.log(IDs);
  
              $('#next-container').html('loading');
  
              $.ajax({
                  url: 'wp-content/themes/freakyshape/inc/load_post.php',
                  type: 'POST',
                  data: {'post_ids[]': IDs },//'post_ids='+IDs,
  
                  success: function($data) {  
                      $container.isotope( 'insert', $data);
  
                  }
              })
      })
  })
  </code></pre>