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' =>...
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://...
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 (
'...
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,
'...
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 ...
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() &...
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',
[
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 = ...
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 ...
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(
...
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 ...
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, ...
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',
'...
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 ...
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(
...
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'] )...
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 ...
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() )
...
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, ...
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' ...
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 ...
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 ...
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' ...
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' => '...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
tax-query × 274wp-query × 147
custom-taxonomy × 88
custom-post-types × 46
taxonomy × 45
meta-query × 31
terms × 26
advanced-taxonomy-queries × 22
woocommerce-offtopic × 20
query × 18
pre-get-posts × 18
query-posts × 13
categories × 12
get-posts × 12
php × 10
loop × 10
search × 9
order × 9
multi-taxonomy-query × 9
posts × 5
functions × 4
customization × 4
tags × 4
array × 4
custom-field × 3