Show only WooCommerce in stock products with a WP_Query
问题 I have this code, it shows the best sales, but it also shows the product without stock, how do I modify the code. so that it only shows the products with stock? . Thanks ! $best_sellers_args = array( 'post_type' => 'product', 'meta_key' => 'total_sales', 'posts_per_page' => 6, 'orderby' =>'meta_value_num', 'order' => 'DESC' ); $products = new WP_Query( $best_sellers_args ); 回答1: Since WooCommerce 3, there is 2 ways to exclude "Out of stock" products on your WP_Query : 1) Including a Tax query