new WP_Query to get max price meta value not working

As @Milo suggested and also codex documented it is_main_query Under_the_Hood This function is an alias for the method WP_Query::is_main_query(). In filter or action hook callbacks that are passed the WP_Query object, such as pre_get_posts, it is circular to call this function. Instead, directly call the passed object’s method. For example, if your filter callback assigns … Read more

Orderby the sum of several numeric custom meta fields

This is definitely not within realm of native orderby parameters in query. They are limited to an order by individual meta fields and have no ways to implement aggregate of them. You would have to either write custom SQL for it or query a broader set and finalize calculations on PHP side. It is hard … Read more

How to build a WP_Query using mulitple tags and using AND or OR operator between them

Give something like this a try: (it came from the same page you linked to, just scroll down a bit more). $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, // searches for posts meeting both conditions array( ‘taxonomy’ => ‘midgets’, ‘field’ => ‘slug’, ‘terms’ => array( ‘tagA,TagB’ ), // searches for … Read more

Adding an array from a query string to a WP meta_query

This $_GET[‘variable’] is an array, as per your URL query string ?variable[]=value1&variable[]=value2, $_GET[‘variable’][0] and $_GET[‘variable’][1] should return those 2 key values Edit – after the discussion – making it dynamic $meta_query = array(); if ( ! empty( $_GET[“variable”] ) ) { if ( is_array( $_GET[“variable”] ) ) { $meta_query[‘relation’] = ‘OR’; foreach ( $_GET[“variable”] as … Read more

Populate tax_query terms parameter with post term

You have a couple of issues here. As your code stand, $post is undefined. It is actually better to make use of get_the_ID() to get the post ID instead of $post wp_get_post_terms() makes an extra db call, so if you are really set on performance, I would rather use get_the_terms() You are returning term names, … Read more

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