I'm trying to fetch posts in ajax. Everything is working but It is showing only one post. Please check my code and tell me if something is wrong
function ag_get_posts() {
global $post;
$args = array(
'post_type' => 'post',
'posts_per_page' => 12,
'post_status' => 'publish',
);
query_posts( $args );
while ( have_posts() ) : the_post();
locate_template( 'post.php', TRUE, TRUE );
endwhile;
wp_reset_query();
exit;
}
add_action('wp_ajax_ag_get_posts', 'ag_get_posts');
jQuery:
var data = {
action: 'ag_get_posts',
};
jQuery.post(AjaxPath.ajaxurl, data, function(response) {
var result = $(response)
Content.html(result);
});