Home can't replace child taxonomy of a parent taxonomy using custom post type with ajax wodpress
Reply: 0

can't replace child taxonomy of a parent taxonomy using custom post type with ajax wodpress

Suleman
1#
Suleman Published in 2018-01-12 12:41:21Z

I am working custom post types with ajax on http://experiments.sulemanfreelancer.com/ajax-with-custom-post-type/

So far so good. I have got stuck in a condition that I am not able to make.

I am using categories -> Single Post, child categories -> Single Post, child categories -> child categories -> Single Post.

Like if you click smart phones -> Samsung -> Galaxy Note -> Galaxy Note II - > 32 GB you will see the single product/post which is "Galaxy Note 2 32 GB".

Now when I click Apple it goes under all the samsung categories list. I want it replace all the samsung categories and show only apple categories step by step as I click.

My ajax code is :

<script>
function cat_ajax_get(catID,catslug,obj) {
    jQuery("a.ajax").removeClass("current");
    jQuery(obj).addClass("current"); //adds class current to the category menu item being displayed so you can style it with css
    jQuery("#loading-animation").show();
    jQuery("#category-post-content").hide();
    var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); //must echo it ?>';
    var link_category = jQuery(obj).attr("data-category");
    var target_word = catslug;
    jQuery.ajax({
        type: 'POST',
        url: ajaxurl,
        data: {"action": "load-filter", cat: catID },
        success: function(response) {   y("#category-post-content").append('<div class="section" id="'+ catslug +'">' +response+ '</div>');
            }*/
            jQuery("#category-post-content").append('<div class="section" id="'+ catslug +'">' +response+ '</div>');
            jQuery("#loading-animation").hide(); 
            jQuery("#category-post-content").show();
            return false;
        }
    });
}
</script>

My php code for ajax call is:

<?php foreach ( $categories as $cat ) { ?>
    <li id="cat-<?php echo $cat->term_id; ?>"><a class="ajax" data-category="<?php echo $cat->slug; ?>" onclick="cat_ajax_get('<?php echo $cat->term_id; ?>','<?php echo $cat->slug; ?>',this);"><?php echo $cat->name; ?></a></li>
<?php } ?>

my template file for displaying ajax loaded content:

<div id="loading-animation" style="width:100px;display: none;">
    <img src="<?php echo admin_url ( 'source.gif' ); ?>"/>
</div>
<div id="category-post-content" style="display: block; float: left;width: 100%;">
</div>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336237 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO