Using tax_query creates a 1 = 0 or 1 = 1 in $wp_query->request
This is my first attempt at modifying the main query using the pre_get_posts action/filter
This is the function currently hooked to it:
This is a plugin built on top of a WooCommerce installation. So basically this function tries to support searching a WooCommerce product either through the standard search (title and content) or an attribute search on a custom attribute called Ordering Code which is pa_ordering-code in the term_taxonomy table
Other parts of the code works fine, I can modify the s and post__not_in vars without any problems, but if I try to use the tax_query it, the query seems to break down.
To give you an idea, when I try this:
dumping the WHERE clause, I see this:
AND wp_posts.ID NOT IN (219) AND 0 = 1 AND ( ( (wp_posts.post_title LIKE '%foo%') OR (wp_posts.post_content LIKE '%foo%') ) AND ( (wp_posts.post_title LIKE '%foo bar%') OR (wp_posts.post_content LIKE '%foo bar%') ) ) AND wp_posts.post_type = 'product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( ( wp_postmeta.meta_key = '_visibility' AND CAST(wp_postmeta.meta_value AS CHAR) IN ('visible','search') ) )
Notice the AND 0 = 1? When I dump the JOIN clause, I become sure that the tax_query parameter isn’t being interpreted properly since I only see the postmeta table in there. No terms, term_relationships, or term_taxonomy table.
And I also tried simply overwriting the existing tax_query (if there is one) by doing this:
$args = array( array( 'taxonomy' => 'pa_ordering-code', 'field' => 'name', 'terms' => array($keyword), 'operator' => 'LIKE' ) ); $query->set('tax_query', $args);
But I still could not get it to work. Any ideas as to what I may be doing wrong?
- The topic ‘Using tax_query creates a 1 = 0 or 1 = 1 in $wp_query->request’ is closed to new replies.