Tag Info

Hot answers tagged

9

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' => ...


6

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


6

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' ) ...


5

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


4

The reason this isn't working is because 'tax_query' needs to be an array of arrays (confusing, I know). ... 'tax_query' => array( array( 'taxonomy' => 'build-type', ... It is that way so you can group a few different rules together.


4

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


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


3

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


3

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' => ...


3

AFAIK $query->get for main query works only with public query vars, i.e. vars that can be triggered via url, but nothing prevents to directly access directly to tax_query property of query, but notice that it is an object, instance of WP_Tax_Query and the current queried taxonomy arguments are in the queries property of that object. Accessing to that ...


3

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', ...


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

The only option you have is to write your own SQL into the posts_clauses filter, where you get an array of the JOIN, WHERE, ORDER, etc. clauses that you can alter, add to, remove, etc. One MAJOR MAJOR note on this, is ALWAYS use the global $wpdb's prepare function, which will sanitize all your lovely datas. You don't want to be allowing any type of ...


2

Found problem. I replaced: $posts = $query->get_posts(); with: $posts = array(); if ($query->have_posts()){ while ($query->have_posts()){ $query->next_post(); array_push($posts, $query->post); } } And everything is working now.


2

'terms' => array('$tags1'), Remove the single quotes and it should look like 'terms' => array($tags1) OR 'terms' => $tags1 No need to make it an array, if you are using just one value.


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

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

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


2

Because $imgID is an array of post objects. Instead of: return $imgID; You need: return $imgID ? key( $imgID ) : 0; Since get_children returns an array of posts indexed by their ID, you can simply use key to return the value of the first one.


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

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

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

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

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

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

You can do everything you need using the search parameters allowed in WP_Query -- except searching in the post title only. In order to do that, see this answer. Make sure to look at the taxonomy and meta subqueries allowed in the args passed to WP_Query. EDIT: Since you need to select using OR, you have 2 options -- you could run 2 queries and merge the 2 ...


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

Answering myself, the problem was the 'AND', must be 'OR', thank you anyway.


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