Meta Query Builder
Meta comparisons with the right compare operator and the right cast — so "9" does not come out greater than "10".
Clauses
2 clauses · 2 JOINs
Matchevery clause must match
price<=
meta_value cast to NUMERIC <= 5000
in_stock=
meta_value = 1
The query around it
no_found_rows
Skips the COUNT query — right whenever you are not paginating.
A secondary query with its own loop and wp_reset_postdata().
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io). $args = array( 'post_type' => 'product', 'posts_per_page' => 12, 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_key' => 'price', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'price', 'value' => 5000, 'compare' => '<=', 'type' => 'NUMERIC', ), array( 'key' => 'in_stock', 'value' => '1', ), ), ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { echo '<ul>'; while ( $query->have_posts() ) { $query->the_post(); printf( '<li><a href="%1$s">%2$s</a> %3$s</li>', esc_url( get_permalink() ), esc_html( get_the_title() ), esc_html( get_post_meta( get_the_ID(), 'price', true ) ) ); } echo '</ul>'; wp_reset_postdata(); } else { esc_html_e( 'Nothing matched.', 'mytheme' ); }