tax_query will produce nothing

Looking at the WP_Query documentation on tax_queries we can see it accepts a nested array as a parameter. Compare that to the provided code: ‘tax_query’ => array( ‘taxonomy’ => ‘news_category’, ‘field’ => ‘term_id’, ‘terms’ => 82, ), Should look like: ‘tax_query’ => [ [ ‘taxonomy’ => ‘news_category’, ‘field’ => ‘term_id’, ‘terms’ => 82, ] ],

if wp_query taxonomy term have posts

I’m not sure what you exactly need, but normally, by default, get_terms returns only terms that actually have posts assigned to them $terms = get_terms( ‘exhibition’ ); var_dump( $terms ); Apart from this, I really do not know what you exactly need

Order posts by (hierarchical custom) taxonomy terms and term children

This query will handle two levels of hierarchy in your taxonomy. More than two levels of hierarchy and you’ll need a recursive self-join. What this does is return the posts in the correct child within parent order. To create the appropriate parent level headings, you’ll have compare the current post’s parent taxon with that of … Read more

How to create a WP_Query to search the Title or Tag?

Please use below code to show posts in texonomy and titles $s = $request[‘s’]; $tags = str_replace(‘ ‘, ‘-‘, strtolower($request[‘s’])); $q1 = get_posts(array( ‘fields’ => ‘id’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘s’ => $s )); $q2 = get_posts(array( ‘fields’ => ‘ids’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘tag’ … Read more

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