Tag Info

Hot answers tagged

6

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


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

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

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


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

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

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

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


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

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


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


1

I may suggest not combining each of these into hierarchical taxonomies, but setting up 3 distinct taxonomies. It seems like they are 3 unrelated properties of the photos, and thus, I would separate the code for them. Then you're not trying to code around nested taxonomy terms, but you can access them each individually. The taxonomies would be color, location ...


1

$wp_query->query_vars['taxonomy'] alone won't do it, but yes, you can check the object itself. However, something like is_tax() may be more appropriate. A lot depends on context and you query is all but lacking in that.


1

To make pagination work you shoul pass a paged query var. Maybe in a custom page template. then... $tax_per_page = 2; $post_type = 'print'; $taxonomies = get_object_taxonomies( $post_type ); $page = get_query_var('paged') > 1 ? get_query_var('paged')-1 : 0; $splitted_taxes = array_chunk($taxonomies, $tax_per_page); $taxonomies_on_page = ...


1

As discussed in chat and as @Rarst already told you, there's no default WordPress way to accomplish Archive of multiple taxonomies and all their terms In fact there's no way to accomplish Archive of single taxonomy and all its terms in WordPress. Simply because WordPress doesn't do that - without custom SQL queries. But there're some things you ...


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

If I'm understanding you correctly get_term_children does what you want. $term_id = 2; $tax_name = 'locations'; $term_child = get_term_children( $term_id, $tax_name ); Another possibility would be using get_categories, it has an child_of, taxonomy and depth parameter - the documentation on wp_list_categories, which offers pretty much the same ...


1

See get_the_terms(), you'd do something like so: foreach((get_the_terms($post->ID) as $term) { echo $term->term_id. '<br/>'; }


1

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.


1

You should have a look at this answer. Group by isn't what you want. WordPress, by default, groups by post ID to eliminate duplicate posts from the list. Since you'll need to group by ID and post_type, there will always be only a single combination of post_type and ID (your group by will do nothing, in other words). Instead of hooking into post_groupby use ...


1

Use this function to determine if Taxonomy is hierarchical or not: Function Reference/is taxonomy hierarchical « WordPress Codex Example: // taxonomy term archives $post_type = get_post_type(); $taxonomies = get_object_taxonomies($post_type); if(!empty($taxonomies)){ foreach($taxonomies as $taxonomy){ // only want hierarchical -- no tags please ...


1

Not sure what you mean by "I'd like to keep the post_tags available for use" but I see two options here: $post_type = get_post_type(); $taxonomies = get_object_taxonomies($post_type); $taxonomies = array_diff($taxonomies,array('post_tag')); // and then your Loop Or ... $post_type = get_post_type(); $taxonomies = get_object_taxonomies($post_type); ...



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