AJAX POST FEED
<?php
function ajax_postcall() {
$call_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'cat' => $category_id,
'order' => 'DESC'
);
$args['tax_query'] = array(
array(
'taxonomy' => 'project_categories',
'field' => 'term_taxonomy_id',
'terms' => $this_cat,
),
);
$html = "";
if ( $custom_query->have_posts() ) { while ( $custom_query->have_posts() ) { $custom_query->the_post();
$count = 0;
$post_id = get_the_ID();
$post_title = get_the_title();
$post_link = get_permalink($this_post_id);
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'full')[0];
$html .= "<div class='single_XXXX flex'>";
$html .= " <a href='{$post_link}' class='featured_wrap block'><div class='featured_image backg after_landscape' style='background-image: url({$featured_image})'></div></a>";
$html .= " <div class='text_details_wrap'>";
$html .= " <a href='{$post_link}' class='post_title block'>{$post_title}</a>";
$html .= " <div class='post_excerpt'></div>";
$html .= " <a href='{$post_link}' class='post_button_wrap block'><button></button></a>";
$html .= " </div>";
$html .= "</div>";
$count++;
}}
$result['status'] = 'working';
$result['html'] = $html;
$result = json_encode($result);
echo $result;
die;
}
add_action("wp_ajax_ajax_postcall", "ajax_postcall");
add_action( 'wp_ajax_nopriv_ajax_postcall', 'ajax_postcall' );
<script>
jQuery(document).ready(function($) {
$( ".single_term" ).click(function() { //2AM ON AND OFF
var attribute_id = $(this).attr("data-attribute-id");
var what = $(this);
var what_class = "filter_active";
var has_class = false;
if ($(what).hasClass( what_class )) { has_class = true; }
if (has_class == false) {
$(what).addClass(what_class);
}else{
$(what).removeClass(what_class);
}
ajax_postcall();
});
function ajax_postcall() {
$('#postsfeed_content_wrap_1').html("<div class='loading_text blink'>LOADING</div>");
if (window.FormData) {
formdata = new FormData();
//formdata.append("something", something);
formdata.append("action", "ajax_postcall");
}
if (formdata) {
$.ajax({
url: '/wp-admin/admin-ajax.php',
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (res) {
response = JSON.parse(res);
//alert(response.status);
//alert(response.amount);
//$('.result_wrap').css('display','inline-block');
//$(result_id).html(response.amount);
$('#postsfeed_content_wrap_1').html(response.html);
}
});
}
}
ajax_postcall();
});
</script>