Posted By

i3ad on 07/05/14


Tagged


Versions (?)

WPML-Query


 / Published in: PHP
 

WPML-Query

  1. <?php
  2.  
  3. $term_args=array(
  4. //'exclude' => array(23),
  5. 'hide_empty' => true,
  6. 'parent' => 0, // only top-level
  7. 'taxonomy' => 'product_cat'
  8. );
  9.  
  10. $terms = get_terms('product_cat', $term_args);
  11.  
  12. if ($terms) {
  13. foreach( $terms as $term ) { ?>
  14.  
  15. <div class="wrapper">
  16.  
  17. <h3 class="title">
  18. <?php echo $term->name; //display name ?>,
  19.  
  20. TERM-ID:<?php echo $term->term_id; ?>,
  21. ICL-ID:<?php echo icl_object_id($term->term_id, 'product_cat', false); ?>
  22. </h3>
  23.  
  24. <hr>
  25.  
  26. <?php
  27.  
  28. $the_term_id = $term->term_id;
  29. $icl_term_id = icl_object_id($term->term_id, 'product_cat', false);
  30.  
  31. $args=array(
  32. 'post_type' => 'product',
  33. 'post_status' => 'publish',
  34. 'posts_per_page' => 4,
  35. 'ignore_sticky_posts'=> 1,
  36. 'orderby' => 'date',
  37. 'suppress_filters' => 0,
  38. 'tax_query' => array(
  39. 'taxonomy' => 'product_cat',
  40. 'field' => 'id',
  41. 'terms' => $the_term_id,
  42. #'terms' => $icl_term_id,
  43. 'include_children' => true,
  44. 'operator' => 'IN'
  45. )
  46. )
  47. ); $query = new WP_Query( $args ); ?>
  48.  
  49. <?php while ( $query->have_posts() ) : $query->the_post(); ?>
  50.  
  51. <?php wc_get_template_part( 'content', 'product' ); ?>
  52.  
  53. <?php endwhile; // end of the loop. ?>
  54.  
  55. </div>
  56.  
  57. <?php
  58. }; // END foreach term
  59. }; // END if terms
  60. wp_reset_postdata(); ?>

Report this snippet  

You need to login to post a comment.