php - Display product under its category -


i working in wordpress.i have display different subcategory.now click on each category display product under it.

my code this:

<?php     $query3 = "select t.* wp_terms t                 join wp_term_taxonomy tt on tt.term_id = t.term_id                tt.parent = ".$res2->term_id;     $result3 = $wpdb->get_results($query3);      foreach($result3 $res3)     { ?>         <li>             <a href="##" class="sub_cat_name" data-id = "<?php echo $res3->term_id; ?>"><strong><?php echo $res3->name; ?></strong></a>                 <ul class="tmp">                      <li class="tmp_li">                      </li>                 </ul>         </li> <?php      } ?> 

and jquery code is:

<script> $(document).ready(function(){     $(".sub_cat_name").click(function(){         var cat_id = $(this).data("id");         //alert(cat_id);         $.ajax({             url : "<?php echo site_url()."/category-products/?cat_id=" ?>" + cat_id,         }).done(function(data){             $(".tmp_li").html(data);             });         });     }); </script> 

and ajax page :

<?php /**      template name: category products */ $cat_id = $_get['cat_id']; //echo $cat_id;  $query = "select p.* wp_terms t          join wp_term_taxonomy tt on tt.term_id = t.term_id         join wp_term_relationships tr on tr.term_taxonomy_id = tt.term_taxonomy_id         join wp_posts p on p.id = tr.object_id         t.term_id = ".$cat_id; $result = $wpdb->get_results($query); //print_r($result); foreach($result $res)     { ?>     <div class="pro_name">         <?php echo $res->post_title; ?>     </div> <?php   } ?> 

i got product under subcategory.but problem when click on link product display in subcategory.instead of want display products under own category not in all.

for instance

there 2 subcategory:

1) apple

2) mango

when click on apple product display under apple not in mango. here got apple product under apple under mango. code should have write solve issue?

try .... have find relational element appending data.. otherwise append every element has class... if not work minor changes require..

<script> $(document).ready(function(){     $(".sub_cat_name").click(function(){      var subcategoru = $(this);     vat tmp_li = subcategoru.siblings('tmp').find('tmp_li');       var cat_id = $(this).data("id");     //alert(cat_id);     $.ajax({         url : "<?php echo site_url()."/category-products/?cat_id=" ?>" + cat_id,     }).done(function(data){               tmp_li.html(data);         });     }); }); </script> 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -