Woo Commerce using WP_Query to get products that match price range, with an additional required product attribute

Your mixing up your meta query and tax query. try this: $params = array( ‘posts_per_page’ => 20, ‘post_type’ => array(‘product’, ‘product_variation’), ‘meta_query’ => array( array( ‘key’ => ‘_price’, ‘value’ => $_POST[‘product_price_min’], ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ), array( ‘key’ => ‘_price’, ‘value’ => $_POST[‘product_price_max’], ‘compare’ => ‘<=’, ‘type’ => ‘NUMERIC’ ), ), ‘tax_query’ => … Read more

WP_QUERY wrong ammount of posts

But all of them get obtained from the database. The problem is that you’re ignoring half of them. Or rather merging two of them and displaying as one. Let’s take a look at your code: while ( $query->have_posts() ) { $query->the_post(); // <- here you call the_post() first time $output.='<div class=”entry filter_product”>’; // and in … Read more

AJAX Breaking Offset Argument In WP Query

So I’m guessing this is a follow-up to this question. And based on my answer there, you can use/add the offset parameter like so: In category.php, just set the preferred offset: $the_query = new WP_Query( array( ‘category__in’ => array( $cat_id ), ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ‘paged’ => $current_page, ‘offset’ => 1, // set … Read more

WP_Query author parameter not working

First, the author parameter is parsed and appended to the author__in and author__not_in query parameters. Then author__in or author__not_in array is processed. These can be arrays created from author parameter or arrays passed as query parameteres author__in / author__not_in or created from a mergion author parameter with author__in / author__not_in parameters. Parameters author__in and author__not_in … Read more

Query where ANDing slug values not working

You can do this using the WP APIs like this: $args = [ ‘post_type’ => ‘post’, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘your_taxonomy_name’, ‘field’ => ‘slug’, ‘terms’ => array( ‘arizona’, ‘speech-language-pathology’ ), ] ], ]; $query = new WP_Query( $args ); Then you can use $query as you would any standard post … Read more

WP_QUERY with group by with custom fields

(Revised answer) So after discussing via the comments, what you really need is a custom ORDER BY clause, which in WordPress post queries (WP_Query), you can set the clause via the posts_orderby filter just like you can set custom GROUP BY clause via the posts_groupby filter. The order that I need is June – 2019 … Read more

Hide products in uncategorized category from search results

Try to add the following lines of code at the end of your theme’s functions.php file: function custom_pre_get_posts_query( $q ) { $tax_query = (array) $q->get( ‘tax_query’ ); $tax_query[] = array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array( ‘uncategorized’ ), ‘operator’ => ‘NOT IN’ ); $q->set( ‘tax_query’, $tax_query ); } add_action( ‘woocommerce_product_query’, ‘custom_pre_get_posts_query’ ); … Read more