How to Get WooCommerce featured products in a WP_Query?

Are you looking for a simple way to show featured products on your WooCommerce site? Then you are in the right place! There are many ways to show this using shortcode, plugin, or custom query.

In this tutorial, I am showing this using a custom query. Let’s start…

Step 1: Set products as featured from WooCommerce dashboard

To set a product as featured please follow the below screenshots

Step 2: Please use the below script to get the featured products

// Query
$query = new \WP_Query(array(
    'post_type'             => 'product',
    'posts_per_page'        => 5,
    'order'                 => 'DESC, // use DESC or ASC
    'ignore_sticky_posts'   => 1,
    'tax_query' => array(
            'taxonomy' => 'product_visibility',
            'field'    => 'slug',
            'terms'    => 'featured',
            'operator' => 'IN', // or 'NOT IN' to exclude feature products

That’s it!

Happy coding. Thanks!







Leave a Reply

Your email address will not be published. Required fields are marked *