Created
April 13, 2018 06:32
-
-
Save markduwe/7997db5502e59dfe4aa52cd4b3b46793 to your computer and use it in GitHub Desktop.
Gets a list of Woocommerce categories that have featured products and outputs them
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
<?php | |
$types = get_terms( array( | |
'taxonomy' => 'product_cat', | |
'hide_empty' => true, | |
'field' => 'slug' | |
)); | |
foreach($types as $type) { | |
$args = array( | |
'post_type' => 'product', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => $type->name, | |
), | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'product_visibility', | |
'field' => 'name', | |
'terms' => 'featured', | |
) | |
) | |
); | |
$loop = new WP_Query($args); | |
if($loop->have_posts()) : | |
?> | |
<h2><?php echo $type->name; ?></h2><!-- category title --> | |
<?php | |
while ($loop->have_posts()) : $loop->the_post(); | |
?> | |
<!-- loop stuff --> | |
<?php | |
endwhile; | |
wp_reset_postdata(); | |
endif; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment