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

user2710 Published in April 22, 2018, 4:55 am

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 :

function cat_ajax_get(catID,catslug,obj) {
    jQuery(obj).addClass("current"); //adds class current to the category menu item being displayed so you can style it with css
    var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); //must echo it ?>';
    var link_category = jQuery(obj).attr("data-category");
    var target_word = catslug;
        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>');
            return false;

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 id="category-post-content" style="display: block; float: left;width: 100%;">
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO