WooCommerce product query for stock status. You can have multiple meta_query filters. See (http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters). By default the relationship between these filters is AND which is ok. You can add a filter for _back_order = no.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $query = array( 'post_type' => 'product', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'instock' ), array( 'key' => '_backorders', 'value' => 'no' ), ) ); $wp_query = & new WP_Query($query); while ($wp_query->have_posts()) : $wp_query->the_post(); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.