Adding a tax_query to a WP_Query Object

If you instantiate WP_Query with arguments, as in your second example, then the query is performed right away, and setting new arguments will not change the results. $q = new WP_Query( [ ‘post_type’ => ‘post’ ] ); $q->set( ‘tax_query’, [] ); // Too late. If you instantiate WP_Query without arguments, like this: $q = new … Read more

simple tax_query intersection

As jdm2112 and SallyCJ said in the comments, the query lacks of ‘field’ => ‘slug’. So: ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘link-category’, ‘terms’ => $link, ‘field’ => ‘slug’ ], [ ‘taxonomy’ => ‘despacho’, ‘terms’ => $despacho, ‘field’ => ‘slug’ ], ],

Query with meta_query and tax_query together not working properly

Tax query is formed wrong. It also array of arrays(queries) get_posts([ ‘meta_query’ => [ [ ‘key’ => ‘country’, ‘value’ => ‘Japan’, ‘compare’ => ‘LIKE’ ] ], ‘tax_query’ => [ [ ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => [‘kids’] ] ] ]); the array should look like this: Array ( [meta_query] => Array ( [relation] … Read more

How to display Related Posts based on number of taxonomy terms matched

Let’s split the problem up in three bits: retrieving the related posts from the database, sorting them and displaying the result. Post retrieval This is possible using the taxonomy parameters offered in WP_Query. Let’s first retrieve the category of the current post and find their IDs: $categories = get_the_terms( get_the_ID(), ‘news-category’ ); foreach ( $categories … Read more

Hiding taxonomies with no children WP_Query & tax_query

UPDATE! OK!!! Woooohooo! Found out what it was.. I should have been calling if have posts before the call for $tax->name; Here is my final, and working code! 🙂 <?php /**********************************************/ // CUSTOM WINE MENU SHORTCODE /**********************************************/ add_shortcode( ‘wine_list_per_cat’, ‘wine_list_per_cat’ ); function wine_list_per_cat($atts){ global $woocommerce_loop; extract(shortcode_atts(array( ‘cat’ => ”, // list of categories in the … Read more

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