Two options-
load a page fragment using jQuery’s load method (see Loading Page Fragments),
or create your own ajax function to load posts and return it in whatever markup you wish:
add_action('wp_ajax_my_ajax_get_posts', 'my_ajax_callback');
add_action('wp_ajax_nopriv_my_ajax_get_posts', 'my_ajax_callback');
function my_ajax_callback() {
$args = $_POST['myargs'];
$collected_child_posts = new WP_Query($args);
echo 'some stuff';
die();
}
pass the admin-ajax url to your javascript via wp_localize_script, or put it directly in your template via admin_url('admin-ajax.php');
then call admin-ajax.php
and pass your ajax action:
jQuery(document).ready(function($){
$.post(your_ajaxurl, {
action: 'my_ajax_get_posts',
myargs: args
},
function(data) {
alert(data);
});
});
the first method is obviously simpler, but the second is easier on the server since a lot less of WP is loaded to execute an ajax call this way, plus less data is getting sent.