Hot answers tagged tax-query
4
This can be done by using the term_taxonomy_id rather than the slug, which will effectively ignore whichever taxonomy is specified and just look at the unique term_taxonomy_id field. This will allow you to effectively be able to do a mixed relationship. You'd want to use an overall relation of AND and put all the terms that should be related OR in one item ...
4
The tax_query parameter is an array of arrays, not just an array.
This:
'tax_query' => array(
'taxonomy' => 'video_type',
'terms' => 'episode',
'field' => 'slug',
'include_children' => true,
'operator' => 'IN'
),
Should instead be this:
'tax_query' => array(
array(
'taxonomy' => ...
3
If you look at the documentation for WP_Query taxonomy parameters, you'll see that the tax_query is an array of arrays.
So:
'tax_query' => array(
array(
'taxonomy' => 'product-type',
'terms' => array('software'),
'field' => 'slug'
)
)
3
You can do this with just get_terms - this allows you to fetch all (or some) of the terms from one (or more) taxonomies.
By default it excludes 'empty' terms, so you'll need to set the arguments appropriately.
//Array of taxonomies to get terms for
$taxonomies = array('category','post_tags','my-tax');
//Set arguments - don't 'hide' empty terms.
$args = ...
2
You can define the args outside of the WP_Query instantiation:
<?php
$tax_query = array('relation' => 'AND');
if (isset($search_course_area))
{
$tax_query[] = array(
'taxonomy' => 'course-area',
'field' => 'id',
'terms' => $search_course_area
);
}
if ...
2
At a glance, I would guess that the problem is your use of
'relation' => 'AND'
Using AND means that you will only return items that fall into all of the taxonomy terms. If you want to return items have any of the taxonomy items, change it to
'relation' => 'OR'
If that "doesn't work", please provide more details about what "it doesn't work" means ...
2
Drew was right, tax-query needs to be an array of arrays
The final solution is:
// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, 'build_type_id', true);
// run query
query_posts(array(
'post_type' => 'portfolio',
'showposts' => -1,
'tax_query' => array(
array(
...
2
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 mimic.
$terms_in = ...
2
tax_query takes an array of tax query arguments arrays (it takes an array of arrays) but you are using only single array. The correct code is as following.
$uposts = get_posts(array(
'post_type' => 'product',
'numberposts' => -1,
'tax_query' => array(array(
'taxonomy' => $cat->taxonomy,
'field' => 'slug',
'terms' => ...
2
tax_query takes an array of arrays. You have an array of arrays of arrays. var_dump($tax_queries); and will get this:
array(1) {
[0]=>
array(1) {
[0]=>
array(3) {
["taxonomy"]=>
string(15) "difficulty_mode"
["terms"]=>
NULL
["field"]=>
string(4) "slug"
}
}
}
Try it without the square ...
2
You can't set query parameters after the query happens, set them before you make the query-
$args = array(
'post_type' => 'articles',
'paged' => $paged,
);
if( some condition )
$args['tax_query'] = array( your tax params );
$query = new WP_Query( $args );
2
we meet here again :)
Try using this:
$term_list = wp_get_post_terms( $post->ID, 'persons', array( 'fields' => 'ids' ) );
and
'tax_query' => array(
array(
'taxonomy' => 'persons',
'field' => 'id',
'terms' => $term_list
)
),
AFAIK, the tax_query accepts field by id or slug only (see here. ...
2
First of all, you run register_post_type on init and register_taxonomy on after_setup_theme which is called after init. This means your custom taxonomy will not be available when registering the post type. I would suggest you remove the taxonomies keyword from the register_post_type arguments array, and just register the taxonomy manually at afterwards. I n ...
2
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 the prior post. Print the ...
1
When you're doing a tax_query or meta_query in a WP_Query, you always have to use an 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(
...
1
You aren't looping through the results. Here is your code:
$m = new WP_Query( $myquery );
if ( $m->have_posts() ) : $m->the_post();?>
<ul><li <?php post_class();?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li></ul>
<?php endif;
wp_reset_postdata(); ?>
There ...
1
The problem is explained in the quote you've mentioned:
"Default value is 'publish', but if the user is logged in, 'private' is added. And if the query is run in an admin context, protected statuses are added too. By default protected statuses are 'future', 'draft' and 'pending'."
Ajax call is always considered to be from an admin context.
1
That seems to be impossible. Please someone correct me if I'm wrong.
The meta_query parameter will actually be transformed into a WP_Meta_Query object, and the relation verification won't go deeper in wp-includes/meta.php, and occurs just once in the top level:
if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) ...
1
Have you tried simply omitting the 'terms' key from the 'tax_query' array?
$query03 = array(
'numberposts' => 5,
'post_type' => array(
'video'
),
'tax_query' => array(
array(
'taxonomy' => 'product',
'field' => 'slug'
)
)
);
Alternately, I wouldn't really worry about ...
1
Is your post type non-hierarchical like a post - or hierarchical like a page?
It will determine which slug parameter you should be using in WP_Query:
name (string) - non-hierarchical (post) slug.
pagename (string) - hierarchical (page) slug.
Also, the tax_query should have the operator parameter. Possible values are 'IN', 'NOT IN', 'AND'. You should set ...
1
Try this again removing operator and relation arguments as follows: here is a useful link http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/
$products = get_posts(array(
'post_type' => 'products',
'posts_per_page' => -1,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => ...
1
The term parameter should actually be terms, even when providing just one term:
$args = array( 'post_type' => 'course',
'tax_query' => array(
array(
'taxonomy' => 'course_codes',
'field' => 'slug',
'terms' => ...
1
Turned out to be a plugin conflict. I had turned off all plugins at one point to no noticeable benefit, but then turned a few back on so I could run some other things on the site I was working with.
The trouble was with the Easy Custom Content Types plugin (a very handy plugin) and I'm checking in with the developer of it. It looks like I may not have the ...
1
Seems like the easiest thing to do is to apply the tax query only if at least one "experience" term has been specified. Something like:
// Get passed vars
$experience = $_GET['experience'];
// Start building the args array
$args = array(
'post_type' => 'page',
);
// If any experience items were passed
if( is_array( $experience ) && ...
Only top voted, non community-wiki answers of a minimum length are eligible