Skip to content

Instantly share code, notes, and snippets.

@Sanabria
Forked from lmartins/front-page.php
Created September 13, 2023 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sanabria/6f4df75039bfa7f7aaad545454fe07e4 to your computer and use it in GitHub Desktop.
Save Sanabria/6f4df75039bfa7f7aaad545454fe07e4 to your computer and use it in GitHub Desktop.
WooCommerce custom loop for Featured Products
<?php
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => 6
);
$featured_query = new WP_Query( $args );
if ($featured_query->have_posts()) :
?>
<ul class="products">
<?php
echo "<h3>" . __("Featured Products") . "</h3>";
if ( $featured_query->have_posts() ) {
while ( $featured_query->have_posts() ) : $featured_query->the_post();
woocommerce_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>
</ul><!--/.products-->
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment