Last active
June 8, 2016 15:39
-
-
Save chrismademe/e482db23a961f7e628c45970be1e6a0f to your computer and use it in GitHub Desktop.
Get Products with a particular Tag (WooCommerce)
This file contains 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 | |
// Get tagged products | |
$featured_products = get_posts(array( | |
'posts_per_page' => 3, | |
'post_type' => 'product', | |
'product_tag' => 'featured', | |
'orderby' => 'date' | |
)); | |
// Loop over them | |
foreach ( $featured_products as $product ): | |
$product = wc_get_product($product->ID); // Replace WP_Post object with WC_Product | |
?> | |
<div class="product"><?php echo $product->get_title(); // Do some stuff ?></div> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment