Empty tax_query array returns an empty array

As already hinted by @Milo, check if you have terms before appending your tax_query You can try the following: (Requires PHP 5.4+ due to short array syntax, revert to old syntax if necessary) $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 15, ‘paged’ => $paged, ‘post__not_in’ => $exclude, ‘s’ => $filter, ]; // Append our … Read more

Is it faster to query records using $wpdb instead of Wp_Query?

Yes, custom SQL queries are in essence faster than a custom instance of WP_Query. The disadvantage of a custom SQL query is that you are loosing a lot, like object cache, filters and actions, etc, etc, and it is also discouraged to use custom SQL if WordPress already offers that specific functionality. WP_Query does have … Read more

How would I format a query that depends on post parent taxonomy

You can still use get_posts: $parents = get_posts( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘my_custom_post_type’, ‘fields’ => ‘ids’, // Just get IDs, not objects ‘tax_query’ => array( array( ‘taxonomy’ => ‘my_custom_tax’, ‘field’ => ‘slug’, ‘terms’ => array( ‘foo’, ‘bar’, ), ), ), ) ); $post_ids = get_posts( array( ‘posts_per_page’ => -1, ‘post_parent__in’ => $parents, ‘post_type’ … Read more

WP Query for variable taxonomies

tax_query requires an array of arrays, and $the_taxes is an array of arrays, you’ve already got 99% of your answer. foreach ($taxes as $tax) { $the_taxes[] = array ( ‘taxonomy’ => $tax, ‘field’ => ‘term_id’, ‘terms’ => $terms, ); } $the_taxes[‘relation’] = ‘OR’; $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => $the_taxes, );

is_search was called incorrectly

The Why part In the core is_search() function there’s a check if the global $wp_query is set: global $wp_query; if ( ! isset( $wp_query ) ) { _doing_it_wrong( __FUNCTION__, __( ‘Conditional query tags do not work before the query is run. Before then, they always return false.’ ), ‘3.1.0’ ); return false; } Note that … Read more

How to combine meta_query and post__in in WP_Query

post__in and post__not_in are mutually exclusive. Note: you cannot combine post__in and post__not_in in the same query. http://codex.wordpress.org/Class_Reference/WP_Query Either make the query with post__in and meta_query combination or make the query with post__not_in and meta_query combination. Any of them but not the union of them.

posts_per_page not working

The problem with the second query is due to the way that the parameters are passed. In the original code, two strings are being passed, which is not going to work: $the_query2 = new WP_Query( ‘cat=10’, ‘posts_per_page=1’ ); You can use an array (preferred method): $the_query2 = new WP_Query( array( ‘cat’ => ’10’, ‘posts_per_page’ => … Read more

Is it possible to dynamically get queried term AND taxonomy?

In a taxonomy template, the queried object is an instance of WP_Term, one of whose fields will be the taxonomy the term comes from. So, you can start your taxonomy.php as follows: $queried_object = get_queried_object () ; $args = array ( ‘post_type’ => ‘inventory’, ‘tax_query’ => array ( array ( ‘taxonomy’ => $queried_object->taxonomy, ‘field’ => … Read more

Loop on front-page.php

This is how you would do it. You’re loop is based on being in an archive or index page. (or home) $args = array( ‘posts_per_page’ => 3, ‘post_type’ => ‘post’, //choose post type here ‘order’ => ‘DESC’, ); // query $the_query = new WP_Query( $args ); if( $the_query->have_posts() ): while( $the_query->have_posts() ) : $the_query->the_post(); get_template_part(‘loop’); … Read more