Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $term_id_list = array();
- $query = new WP_Query( $args );
- // loop through every product
- while($query->have_posts()){
- $query->the_post();
- // get categories of product
- $product_terms = wp_get_post_terms( get_the_id(), 'product_cat');
- // check each term id with $term_id_list
- // if this term id not in there, then push it to $term_id_list
- foreach($product_terms as $term){
- if(!in_array($term->term_id, $term_id_list)){
- $term_id_list[] = $term->term_id;
- }
- }
- }
- // make portfolio filter using the category list
- <?php foreach($term_id_list as $term):
- $term = get_term_by( 'id', $term, 'product_cat');
- ?>
- <button data-filter=".product_cat-<?php echo $term->slug; ?>"><?php echo $term->name; ?></button>
- <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment