template_include for search.php makes WordPress think its on the home page

Your problem is that you are not resetting all the needed query variables, like WP_Query::$is_page, WP_Query::$is_single and WP_Query::$is_archive. Also note that ‘pre_get_posts’ is fired for all queries, the main and the secondaries, so you should check that you are working on the main query. Finally, when you get data from $_GETyou should sanitize it before … Read more

Why is my WP_Query not working when tax_query terms are an array?

When you’re doing a tax_query or meta_query in a WP_Query, you always have to use a nested array( array() ); just see the following example for an explanation and pay attention to the relation argument. $packages = new WP_Query( array( ‘post_type’ => ‘vamos-cpt-packages’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘vamos-holiday-types’, ‘field’ => … Read more

The Operator “NOT IN” Does Not Work In tax_query

I suspect you need an array for the terms – although I’m not sure why it would work with “IN” and not with “NOT IN”… But I’d try this: function menta_pre_get_posts( $query ) { if ( !is_admin() && $query->is_search() && $query->is_main_query() ) { $term = get_term_by(‘slug’, get_query_var(‘s’), ‘product_tag’); if ( $term && !is_wp_error( $term ) … Read more

WordPress tax query use operator LIKE

The only option you have is to write your own SQL into the posts_clauses filter, where you get an array of the JOIN, WHERE, ORDER, etc. clauses that you can alter, add to, remove, etc. One MAJOR MAJOR note on this, is ALWAYS use the global $wpdb‘s prepare function, which will sanitize all your lovely … Read more

Tax_query terms ID’s using variable

It looks like you are making an array with a single string inside. Check if making $tax into an array before passing it will work: $tax = array( 19, 18, 214, 226, 20 ); $query_args = array ( ‘post_type’ => ‘works’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘materials’, ‘field’ => ‘term_id’, ‘terms’ => $tax, ) … Read more

pre_get_posts with tax_query causes empty result

You use tax_query incorrectly. Take a look at Codex Page tax_query should be an array which can contain: relation – it should be string (AND/OR) taxonomy term – array with defined taxonomy, field, terms, and so on. In your code your setting tax_query to: $taxquery = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)