Skip to main content
22 votes

Get term by custom term meta and taxonomy

Try This: $args = array( 'hide_empty' => false, // also retrieve terms which are not used yet 'meta_query' => array( array( 'key' => 'feature-group', 'value' =>...
Ahmed Ali's user avatar
  • 321
18 votes

Nested meta_query with multiple relation keys

Meanwhile this is possible, see documentation with example and explanation: Old link: https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters Update: 2021, new link: https://...
Ramon Fincken's user avatar
15 votes
Accepted

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 ( '...
Pedro Coitinho's user avatar
15 votes
Accepted

Wordpress tax_query "and" operator not functioning as desired

not tested but give this a shot 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'image_tag', 'field' => 'term_id', 'terms' => 25, '...
Jeff's user avatar
  • 168
9 votes

Multiple, nested tax_query relation

Just providing an updated answer about Nested Taxonomies because they are indeed supported. The selected answer above is out of date / a little misleading. WordPress Core has supported Nested ...
italiansoda's user avatar
7 votes
Accepted

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() &...
nibnut's user avatar
  • 991
6 votes

"tax_query" parameter not working with WP_Query

It's also worth to pay attention if you are formatting the rules correctly: new WP_Query([ 'post_type' => 'vehicle', 'tax_query' => [ 'relation' => 'OR', [ ...
Lucas Bustamante's user avatar
6 votes

Tax_query not working on multisite

I found out that in order to query wp posts via custom taxonomy, from a blog 1 to another blog 2, you have to register that custom taxonomy in both blogs, otherwhise it won't work. this is strange but ...
hammed's user avatar
  • 91
6 votes
Accepted

Does tax_query really beats meta_query in all situations?

Does tax_query beats meta_query even in situations like this? No. Taxonomies are appropriate if you have a common set of values that are shared by many posts, and you're doing a simple comparison ...
Jacob Peattie's user avatar
5 votes

Wordpress tax query use operator LIKE

As stated in other answers you cannot simply do a LIKE-wise search using tax_query. What you can do is either altering the SQL statement using filters as suggested by @Eric Holmes which is an ...
Arvid's user avatar
  • 151
5 votes
Accepted

WP_Query, tax_query and term_meta: How to?

AFAIK there's no way to achieve that within a single WP_Query, so you'll have to first get a list of term_ids which have a different year than the one in question. I think with the following you'll ...
jgangso's user avatar
  • 1,533
5 votes
Accepted

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 ...
Bram's user avatar
  • 276
5 votes

get_terms with posts that have a different taxonomy with term x

Just to start, you say "I am using get_terms to retrieve all terms from Tax 1 with posts associated with it", however your actual code gets all terms in that taxonomy regardless of whether or not they ...
Jacob Peattie's user avatar
4 votes
Accepted

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 = ...
Paul 'Sparrow Hawk' Biron's user avatar
4 votes

Including all terms in wordpress tax_query

In addition to the marked 'best answer', there is another way which might be even faster because we don't have to pull the terms and extract the names first. This is achieved with a trick by using a ...
Dr. Manuel Lamotte-Schubert's user avatar
4 votes

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( ...
MrFox's user avatar
  • 304
4 votes

Hidden woocommerce products still showing up in search results

This code can't be added anywhere you want, and it can't be added to functions.php or any other php file like this. This is a element for the array used to create the WordPress query object. It has to ...
Milan Petrovic's user avatar
4 votes
Accepted

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, ...
Krzysiek Dróżdż's user avatar
4 votes
Accepted

Get list of terms that have posts in another term

Try replacing 'operator' => 'AND' with 'relation'=>'AND' Updated Code Snippet: $current_color = get_queried_object_id(); $query = new WP_Query( array( 'post_type' => 'product', '...
ViralP's user avatar
  • 310
3 votes

Get term by custom term meta and taxonomy

Building on the answer from ilgıt-yıldırım above, both the get_term_meta statement and $key == 'meta_value' statements need to contain $term>term_id. Here's a complete example including the custom ...
Steven Ryan's user avatar
3 votes
Accepted

WP_Query tax_query on ACF post_object

Update 1 As @Florian pointed out, we do not need to use the wp_list_pluck function, we could simply add the 'fields' => 'ids' to the WP_Query to retrieve the list of ids: $producers = new WP_Query( ...
Chin Leung's user avatar
3 votes
Accepted

tax_query shows no results if nothing is selected

So far good, add taxonomy condition by checking the suburbs and states Value. // Suburbs if( !empty( $_GET['suburbs'] ) ) { $suburbs = $_GET['suburbs']; } // States if( !empty( $_GET['states'] )...
GKS's user avatar
  • 1,306
3 votes
Accepted

List taxonomy / category count showing list published posts only

Checked the source, and it seems the only way to get this done is filtering the output count for each term, you can achieve that by inserting this filter before your get_terms call. Note that this ...
Carl Alberto's user avatar
  • 1,097
3 votes
Accepted

pre_get_posts Remove tax_query Completely

This fixed it! :) Hat-tip gmazzap for the useful info: Obliterate the main query and replace it function wpse_286813_omit_all( $query_vars ){ // triggered also in admin pages if ( is_admin() ) ...
admcfajn's user avatar
  • 1,326
3 votes
Accepted

Custom taxonomy query not working with switch_to_blog

I find the solution: Tax_query not working on multisite (I dont say, that I work with switch_to_blog, because everything is works fine with this function... everything, including postmeta queries, ...
Galgóczi Levente's user avatar
3 votes

get_terms with posts that have a different taxonomy with term x

You could use the tax_query argument, for example: 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'tax1', 'field' => 'slug', 'terms' ...
Alexander Holsgrove's user avatar
3 votes
Accepted

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 ...
nmr's user avatar
  • 4,521
3 votes
Accepted

tax_query: Don’t show posts with parent term when they have a corresponding child term applied

I can see you are trying to be clear but still a really confusingly worded question, broke my brain a bit. I think this might achieve what you want, but I'm not fully sure if I understand you ...
majick's user avatar
  • 5,111
3 votes
Accepted

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' ...
aitor's user avatar
  • 655
3 votes
Accepted

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' => '...
Az Rieil's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible