How to add autocomplete to custom taxonomy for CPT

The logic in the tax query is very unlikely to verify true. Look at it: ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘zip_code’, ‘field’ => ‘slug’, ‘terms’ => array( $term ), ), array( ‘taxonomy’ => ‘city_served’, ‘field’ => ‘slug’, ‘terms’ => array( $term ), ), ), If you read the tax query, it … Read more

Use both meta query and tax query

Would you believe it, as soon as I posted this I remembered I asked a question about a query last year. I had a look over it and I’ve adapted my new query like so: $category_slug = filter_input( INPUT_GET, ‘eventtype’, FILTER_SANITIZE_STRING ); $cat_query = []; if( $event_type ){ $cat_query = [ [ ‘taxonomy’ => ‘eventtype’, … Read more

tax_query returning all posts instead of selective posts in WP_Query

Taxonomy Parameters Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays). This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy arrays. In ‘tax_query’ you should add array of arrays (see … Read more

How can i simulate “taxonomy__in” in query?

You can’t, because of the way categories and general taxonomies operate. Categories are a type of taxonomy, so we are querying one level lower when querying for categories. When you query for category__in => array() it actually looks up what category_terms are queried and queries posts from all those categories. Now this effect we can … Read more

pre_get_posts Tax Query not working for custom author page

Don’t run a new query in the template, modify the main query before it’s run via the pre_get_posts action in the theme’s functions.php file. function wpd_author_query( $query ) { if ( $query->is_author() && $query->is_main_query() ) { // your code to set $current_user_name here $query->set( ‘meta_key’, ‘_writer_relation_added_date_’ . $current_user_name ); $query->set( ‘orderby’, ‘meta_value_num’ ); $tax_query = … Read more

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 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