Tag Info

Hot answers tagged

8

I know this is an old question, but it is a bit confusing and hopefully will help someone. The reason that `$query->set doesn't work is because the query has already been parsed and now we need to also update the tax_query object also. Here is how I did it: function my_tax_query( $query ) { $package_id = 12345; $tax_query = array( 'taxonomy' ...


7

Try [operator] => AND in both the sub-arrays. I think that will work from my reading of WP_Tax_Query::get_sql().


5

After reading your revised question it was easier to comprehend what you are trying to do. My new solution looks like the thing you wanted to do in the first place: it just excludes all posts which are of your custom type but don't have the "yes"-term associated with it: $custom_query = array(); $custom_query['post_type'] = 'any'; // first, query all the ...


5

All with_front does is toggle whether or not a taxonomy link can have something else in front of it ie extra permalink stuff from the permalinks options page. For example with_front set to true makes this possible: blah.com/2011/09/tax/term with it set to false, all you can do is: blah.com/tax/term


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


5

As of Wordpress 3.7 a new action named parse_tax_query was added exactly for this purpose. function kia_no_child_terms($wp_query) { $wp_query->tax_query->queries[0]['include_children'] = 0; } add_action('parse_tax_query', 'kia_no_child_terms'); This hook modifies the values of both query_vars and tax_query. Using the pre_get_posts method ...


4

You can get all of the parents of an object via get_ancestors - $term_id = 42; $your_taxonomy = 'sometax'; $parents = get_ancestors( $term_id, $your_taxonomy );


4

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

Wordpress doesn't have the option to add extra information to taxonomies. There isn't any taxonomy_meta table. So, you have two options. Create a new custom table and save the extra information(image link) there. You can also use options table to store the information. You can follow this post of as it shows how to implement what you are trying to do: ...


3

As I have stated, you can do all of the above in your question with only one shortcode. The idea here would be to Use usort() to sort posts according to term name Pass a string of term names in the order you need to display them to the shortcode FEW IMPORTANT NOTES Never ever use extract(). It is unreliable and extremely hard to debug when it fails. ...


2

I haven't run this code so there may be a syntax error, but the gist is to return userfeed-taxonomy with the terms specified that have featured category OR cities-taxonomy with the terms specified and featured category OR anything else that's not those taxonomies. It's kind of clunky, maybe there is a better way: $query->set( 'tax_query', array( ...


2

As @shanebp suggests, you could use wp_count_terms() like this: $numTerms = wp_count_terms( 'service-category', array( 'hide_empty'=> false, 'parent' => 0 ) ); The above will list All top parent terms, empty or not. This function uses get_terms() functions arguments which can be found in the link or the arguments below: $args = array( ...


2

This turned out to be a quite extensive little project for me. BASIC IDEA My approach was to go with a custom archive page as this seems to be the best approach here. The thing with custom taxonomies is that if you have a structure in place, changing that would become a real messy expedition. Also, I always try to stay away from custom queries if ...


2

See Taxonomy Parameters in Codex. First — areas should probably be in your tax_query as well. Second — you probably need to make use of operator argument in queries (inner ones). I am not sure without testing this out but AND seems like it would for more strict matches than default IN for your mandatory types/features logic.


2

You don't need to 2 array for tax query. You can try this scenario: $args2 = array('post_type' => 'custom', 'tax_query' => array( array( 'taxonomy' => 'events', 'field' => 'slug', 'terms' => array( 'tag1', 'tag-2') ...


2

There was actually a plugin written for this a while back - http://wordpress.org/plugins/taxonomy-images/


2

You can try this version with WP_Query() called only once: <?php $args=array( 'post_type' => 'stiri', 'posts_per_page' => 5, 'taxonomy' => 'stire', 'stire' => 'articole-speciale' ); $recentPosts = new WP_Query($args); ?> <div id="featured" > <ul class="ui-tabs-nav"> <?php $i=0; while ...


2

You can try this SQL query for the taxonomy 'mi_neighborhoods' and let's take POST_ID = 1304 SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON (tt.term_id = t.term_id) INNER JOIN wp_term_relationships AS tr ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.taxonomy IN ('mi_neighborhoods') AND tr.object_id IN (1304) ORDER BY ...


2

Thanks helgatheviking, it didn't work as is but you definitely set me on the right path. I got it working by doing the following: <?php foreach((get_the_terms($post->ID, 'your-taxonomy-here')) as $term) { echo $term->term_id. ''; } ?> Replace "your-taxonomy-here" with your own and your ready to go.


2

get_the_tags() function in deed returns only terms of 'post_tag' taxonomy (tags). If you'd like to get terms of another taxonomies, you'd have to use get_the_terms function (http://codex.wordpress.org/Function_Reference/get_the_terms) $custom_post_tags = get_the_terms( get_the_ID(), 'type' ); //type is a name of custom taxonomy or you can use ...


2

Do a tax-query and then count the result. No need for a custom query with dozens of JOINS. $posts = new WP_Query( array( 'post_type' => 'MYPOSTTYPE', 'tax_query' => array( array( 'taxonomy' => 'TAX_1', 'field' => 'slug', 'terms' => array( 'TERM_TAX_1' ), ...


2

This generalisation of above worked for me: $args = array( 'cat' = -1 ); // e.g. to get list of posts in any category $postobjs = get_posts( $args ); $postids = wp_list_pluck( $postobjs, 'ID' ); $taxonomy = 'mytax' // your taxonomy name $termobjs = wp_get_object_terms( $postids, $taxonomy ); $termlist = array_unique( wp_list_pluck( $termobjs, 'name' ) ); // ...


2

After adding print_r($wp_query); to my template and examining the results, I have discovered URL formats that work. I wrote, in my question, that the following format doesn't work -- in fact, it does - if you spell your custom taxonomy name correctly. example.com/?ctxname=term1+term2 Pretty URLs with the '+' and ',' operators (indicating AND and OR ...


2

I have a solution, but it's a really ugly one. I'd love to hear a better one, but I'm not sure it's possible. WP_Query::get_posts() calls parse_tax_query() twice: first near the start, then again just before getting the SQL from it. There's no single hook that lets me intercept and adjust the value of $tax_query in time to adjust the SQL, so instead I had ...


2

Like Justin Tadlock says in your referenced article, the body_class() provides the ability to add classes dependant on the type of term. Given that you indicate your php knowledge is still growing; this maybe the best solution. The codex provides a list of classes on a body_class enabled: http://codex.wordpress.org/Function_Reference/body_class If that ...


2

i could not get this to work with any combination of pre_get_posts or parse_query. i can do it relatively easily by wiping out the query object after it is made. i don't like it b/c then I'm running the query twice, but i'm at my wit's end with trying to be 'efficient' function kia_no_child_taxonomies(){ if(is_tax()){ $args = array( ...


1

I'd use wp_list_filter() with the operator 'NOT' to compare either the term's name, slug or ID (depending how you want to test for term to be exluded). Untested but something like this should work (assuming that you want to exclude the term with slug 'myslug'): $terms = wp_get_post_terms( $post->ID, 'wedding_cat'); $terms = wp_list_filter($terms, ...


1

The terms for the tax_query should be an array.


1

Nothing stands out as 'wrong' - though you do have a few errors: The third tax_query conditional is missing a closing bracket The third tax_query should be querying precio not $ubicacion. Cast the ID variables as integers I'd suggest putting WordPress into debug mode to highlight any syntax errors. Try doing it for only one taxonomy first, and then add ...


1

setup_postdata will let you use loop functions with post results via get_posts. another option is to use the various filters available to alter WP_Query's behavior- posts_join, posts_where, posts_orderby.



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