title: AJAX call to include php file
body: <p>I have a php file (loopHandle.php) with a wordpress loop inside, which I want to load within a div on my web page.</p>
  
  <p>I make a call using an on click event with a string variable of $date ("2012-6"), this variable is important for my wordpress loop as I will be sorting posts by date.</p>
  
  <p>I decided to take this step by step, so far I have the AJAX call working and responding with the variable $date to my div.</p>
  
  <p>This is how I see things; on the click event I send the variables I want to use over by using this link:</p>
  
  <pre><code>$link_url = esc_url(wp_nonce_url( admin_url('admin-ajax.php?&amp;action=dynamic_date&amp;my_date='.$date), "dynamic_date_nonce")); ?&gt;
  </code></pre>
  
  <p>I'm sending the action, nonce and custom variable over to wordpress' ajax processor (admin-ajax.php) which then triggers a function over in my functions.php. This is where I actually do stuff with the variables I've sent.</p>
  
  <p>Now here is the problem I am facing, how do I respond to the ajax call, using the variables I'm sent and reply with my wordpress loop?</p>
  
  <p>Some options I've thought about:</p>
  
  <pre><code>$wp_loop = if($loop-&gt;have_posts()) { 
  while($loop-&gt;have_posts()) { 
  the_post();
  get_template_part( 'content', get_post_format() );
  } 
  } wp_reset_query();
  $response = new WP_Ajax_Response();
  $response-&gt;add(array(
  'what' =&gt; 'fulldate',
  'data' =&gt; $wp_loop)); 
  $response-&gt;send(); 
  </code></pre>
  
  <p>That was more of a poke it with a stick and see what happens approach. </p>
  
  <p>Another theory would be to use <code>$date = $_GET['my_date];</code> in my <code>handleLoop.php</code>, would I be able to retrieve my variable from somewhere that isn't functions.php? Then could I respond like:</p>
  
  <pre><code>$loopHandle = include(handleLoop.php);
  $response-&gt;add(array(
  'what' =&gt; 'fulldate',
  'data' =&gt; $wp_loop)); 
  $response-&gt;send(); 
  </code></pre>
  
  <p>Anyway, I hope I've conveyed my problem correctly and of course help is very much appreciated.</p>
  
  <p>Edit: I capture the key-pairs using:</p>
  
  <p><code>s.data = $.extend(s.data, { action: url.action, _ajax_nonce: url._wpnonce, my_date: url.my_date });</code></p>