I’m having trouble with my wordpress ajax pulling the full page rather than the template part. The query isnt listening to the get_template_part() and is loading the whole page within it.
my category_loader in themename/inc/wp-ajax.
<?php
function category_loader() {
$cat_name = $_GET['category_name'];
query_posts(array('category_name'=> "cat_name", "order" => 'DESC'));
$output = '';
while (have_posts()) : the_post();
get_template_part( 'content', "categoryloaders");
endwhile;
wp_reset_query();
die($output);
} // end my_custom_handler
add_action( 'wp_ajax_nopriv_category_loader', 'category_loader' );
add_action( 'wp_ajax_category_loader', 'category_loader' );
?>
my jquery script
$(function() {
var ajaxurl = decodeURIComponent(ajaxurl);
$(".cat-checkbox").change(function() {
if(this.checked) {
$('#primary').html("loading....")
var the_cat = $(this).val();
var data = {
action: 'category_loader',
category_name: the_cat
};
$.ajax({
type: "GET",
url: "ajaxurl",
data: data,
success: function(data){
$("#primary").html(data);
}
});
}
else {
alert($(this).val() + ' is unchecked');
}
});
});
my output can be seen at this page, it’s not of any sort of advertising but this is really confusing me right now. Any help would be great!