WP_Query Not Recognizing Taxonomy Parameter in Custom Search

The better option may be to use the pre_get_posts hook instead to modify the query before it gets requested instead of creating your own query. Here’s what it would look like: /** * Modify Theme Queries * – https://developer.wordpress.org/reference/hooks/pre_get_posts/ * – https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts * * @param $query * * @return void */ function theme_pgp( $query ) … Read more

Using foreach loop breaks

I believe your issue is with $vals=get_post_meta($post_id, $key2, true); If you check the codex, the last parameter for get_post_meta is whether to return a single value or array of values. You have set it to true which means return only one value. Try it with false (the default) it should work.

Slow WP_Query for custom post type

That’s a known problem with WordPress and searches involving postmeta. What I’d try to do is to create a new taxonomy for “things” you’re usually searching the most: offer_order_status seems the better candidate, as it can be active or not. I’d create a taxonomy with two elements. That would reduce the time of your search … Read more

Get all products which have both product category

Set include_children to false in the tax_query. $args = array( ‘post_type’ => array( ‘product’, ‘product_variation’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array( ‘shop’, ‘cat1’ ), ‘include_children’ => false, ‘operator’ => ‘AND’, ) ) ); See https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

query_vars filter not working even though query string parameter is present

I’m not sure it quite works like that. Try inspecting $query->public_query_vars instead and I think you’ll see it added in there. The way I usually use it is like this: add_filter( ‘query_vars’, ‘add_test_query_vars’); function add_test_query_vars($vars){ $vars[] = “test”; return $vars; } So the same as you but with a named function. Then I add a … Read more