Tag Info

Hot answers tagged

7

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


6

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


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

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

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

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

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 );


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

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


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

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

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


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

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


1

tax_query is used to get the posts associated with certain taxonomy. {tax} (string) - use taxonomy slug. Deprecated as of Version 3.1 in favor of 'tax_query'. tax_query (array) - use taxonomy parameters (available with Version 3.1). taxonomy (string) - Taxonomy. field (string) - Select taxonomy term by ('id' or 'slug') terms (int/string/array) - ...


1

The pre_get_posts filter is immediately before the loop begins in taxonomy-services.php That is too late. The main query runs long before your template loads. Move your pre_get_posts filter to your theme's functions.php, or a plugin or MU-Plugin file, and you should see the difference.


1

Retrieval of multiple posts in WordPress is almost always handled by WP_Query class (or get_posts() function that wraps it). There is quite a lot of documentation and information to it, but to narrowing it down to your specific case you will need to: set up posts loop for each term pass as arguments to each loop: your post type desired number of posts ...


1

For a Category landing page that only shows each 'product_cat' image that links to a separate page for each category, I have the following template enclosed. It doesn't use $term->term_taxonomy_id but rather $term->term_id. Not sure if it will help, but look it over for differences from what you have. <?php /** * Product taxonomy template */ ...



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