Last active
September 12, 2017 12:18
-
-
Save HelloAlberuni/8ea093f808db8613d3127629604a2b8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$term_slug_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_slug_list | |
// if this term id not in there, then push it to $term_slug_lis | |
foreach($product_terms as $term){ | |
if(!in_array($term->slug, $term_slug_list)){ | |
$term_slug_list[] = $term->slug; | |
} | |
} | |
} | |
// make portfolio filter using the category list | |
<?php foreach($term_slug_list as $term): | |
$term = get_term_by( 'slug', $term, 'product_cat'); | |
?> | |
<button data-filter=".product_cat-<?php echo $term->slug; ?>"><?php echo $term->name; ?></button> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment