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

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.


1

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


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

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


1

If you look at source of get_term() it does hard check for taxonomy and for good reasons (caching, collisions, etc). I see two possible approaches: look for term in every appropriate taxonomy until you match try to query for term by search or name__like in multiple taxonomies using get_terms() and work with results


1

You've converted $taxonomy_id_list to a comma separated string then shoved that string into an array. Your array now looks like array( "1,2,3,4" ); That is not going to match any author ID. You are misunderstanding what implode does. This--1,2,3,4,5,6,7-- is a set of integers. If place in the array like this-- array(1,2,3,4,5,6,7)-- you get an array ...


1

You can load a different template for single posts via the single_template filter. Just use the has_term() function to check if the post has a specific term in your custom taxonomy. function wpa_107626_single_template( $single_template ) { // check if the post fits some condition if ( has_term( 'term1', 'film_cat' ) ) { $single_template ...


1

I think showposts was replaced by posts_per_page in wordpress 2.1. See pagination parameters. Also note that print_r($query) won't return any results because $query variables is WP_Query object; you need to exceute the query. $args = array( 'post_type' => 'contractors', 'posts_per_page' => -1, 'tax_query' => array( ...



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