();
// Your loop code
endwhile;
} else {
echo ‘No products found’;
}
wp_reset_postdata();
This code queries the WordPress database for products, setting the post type to ‘product’, the number of posts per page to -1 (all posts), the post status to ‘publish’, and the meta query parameter to look for either a sale price greater than 0 or a minimum variation sale price greater than 0. If products are found, a loop is run over them for further processing. If no products are found, a message is displayed. Finally, the post data is reset.
Was this code snippet helpful?
YesNo