Get specify category + Jquery + Ajax


Template file

foreach ( $terms as $term ) : ?> echo ”;endif;
?>

jQuery(document).ready(function() {

/*
* Trigger window resize function in javascript
*/
function ESresize(){
if (typeof (Event) === ‘function’) {
// modern browsers
window.dispatchEvent(new Event(‘resize’));
} else {
//This will be executed on old browsers and especially IE
var resizeEvent = window.document.createEvent(‘UIEvents’);
resizeEvent.initUIEvent(‘resize’, true, false, window, 0);
window.dispatchEvent(resizeEvent);
}
}

jQuery(“.nav-link”).click(function(){
jQuery(‘.tab-pane’).addClass(‘visibility-hidden’);
setTimeout(function(){
ESresize();
jQuery(‘.tab-pane’).removeClass(‘visibility-hidden’);
},500);
});

jQuery.fn.almComplete = function(alm){
ESresize();
};
/*
* Trigger window resize function in javascript End
*/
jQuery(‘.getcategorylist’).change(function(){

var formData = jQuery(“#categoryForm”).serialize();
var ajaxurl = ”;

var catID = jQuery(this).val();
var procategory = jQuery(this).data(“cat_tx”);

jQuery.ajax({
type : “POST”,
//dataType : “json”,
url : ajaxurl,
data : {
data: formData,
action : “get_categorydata”,
cat: catID,
taxonomy:procategory
},
success:function(data){
jQuery(‘#products_’+procategory).html( data );

//jQuery(‘.product_list’).html(data); // insert data
//jQuery(“#product_list”).append(data);

/********Trigger window resize function in javascript********/
if (typeof (Event) === ‘function’) {
window.dispatchEvent(new Event(‘resize’));
} else {
var resizeEvent = window.document.createEvent(‘UIEvents’);
resizeEvent.initUIEvent(‘resize’, true, false, window, 0);
window.dispatchEvent(resizeEvent);
}

}
});
return false;
});
});
/********* hash url our product trigger tab start *****************/
jQuery(document).ready(function() {
jQuery(“.main-navigation #top-menu li ul.sub-menu li a”).click(function(event){
var href = $(this).attr(‘href’).split(“#”)[1] ;
if(href === ‘plastic’){
jQuery(“.plastic-tab”).trigger(‘click’);
}else if(href === ‘chemical’){
jQuery(“.chemical-tab”).trigger(‘click’);
}else if(href === ‘dairy-beverage’){
jQuery(“.dairy-beverage-tab”).trigger(‘click’);
}else if(href === ‘furniture-paper’){
jQuery(“.furniture-paper-tab”).trigger(‘click’);
}
});
});
jQuery(window).on(‘load’, function() {
var href = window.location.href.split(“#”)[1];
if(href === ‘plastic’){
jQuery(“.plastic-tab”).trigger(‘click’);
}else if(href === ‘chemical’){
jQuery(“.chemical-tab”).trigger(‘click’);
}else if(href === ‘dairy-beverage’){
jQuery(“.dairy-beverage-tab”).trigger(‘click’);
}else if(href === ‘furniture-paper’){
jQuery(“.furniture-paper-tab”).trigger(‘click’);
}

});
/********* hash url our product trigger tab End *****************/

// DOM ready
$(function() {

// Create the dropdown base
$(“”).appendTo(“nav.product-nav”);

// Create default option “Go to…”
// $(“”, {
// “selected”: “selected”,
// “value” : “”,
// “text” : “Go to…”
// }).appendTo(“nav.product-nav select”);

// Populate dropdown with menu items
$(“nav.product-nav a”).each(function() {
var el = $(this);
$(“”, {
“value” : el.attr(“href”),
“text” : el.text()
}).appendTo(“nav.product-nav select”);
});

// To make dropdown actually work
// To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
$(“nav.product-nav select”).change(function() {
//window.location = $(this).find(“option:selected”).val();
// $(“.nav-link[href=” + $(this).find(“option:selected”).val() + “]”).trigger(“click”);
$(“.nav-link[href='” + $(this).find(“option:selected”).val() + “‘]”).trigger(“click”);
});

$(“.product-tabs .nav-pills li .nav-link”).click(function(){
var a_href= $(this).attr(“href”);
$(“nav.product-nav select”).val(a_href);
});

});

?>

/******************/
Function.php
ajax jquery

/*add_action( 'wp_ajax_get_categorydata', 'get_categorydata' );
add_action( 'wp_ajax_nopriv_get_categorydata', 'get_categorydata' );
function get_categorydata() {

global $post;

$cat_id = $_POST['cat'];

$args = array(
'post_type' => 'products',
'posts_per_page' => -1,
'tax_query' => array(
array(
'hide_empty' => 0,
'taxonomy' => 'products_category',
'field' => 'id',
'terms' => $cat_id,
),
),
);

$query = new WP_Query( $args );
$count = count( $query ); */

echo '

';
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();echo $result;
endwhile;
wp_reset_postdata();
else :
echo 'No posts found';
endif;

die(1);
echo '

';

}
?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.