24

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


15

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


9

Yes, it is possible. And there's an easy guide here. Below is a working code you can add to the theme's main functions.php file: // Adds a custom rule type. add_filter( 'acf/location/rule_types', function( $choices ){ $choices[ __("Other",'acf') ]['wc_prod_attr'] = 'WC Product Attribute'; return $choices; } ); // Adds custom rule values. ...


8

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.


8

Starting from Wordpress 4.4, you can use add_term_meta function to store metadata for a term. This is basically a key-value pair information which is stored in wp_termmeta table. Original Answer(Prior to WP 4.4) 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 ...


7

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


7

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 afterwards. In your ...


7

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


6

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


6

Use the code below: 'rewrite' => array( 'slug' => '.', 'with_front' => false ), Notice that when you rewrite the slug that the default page template is opened, when you go to the taxonomy page.


6

You can use the Advanced Custom Fields plugin to add a custom field (an image field) to your custom taxonomy group.


6

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


5

Firstly, the GUID is not the URL. It is a "globally unique identifier". WordPress uses the URL for this purpose, but accessing it is not a reliable way to get the URL for anything (this was a bad idea, but is kept this way for backwards compatibility). It's not possible to query the image URL from the database directly. The full URL is not stored there. But ...


4

Use this code its work fine 'rewrite' => ['slug' => '/', 'with_front' => false]


4

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


3

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


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


3

This isn't possible via WP_Query, but more importantly, this would be stupendously expensive. Taxonomy queries are expensive. Post meta queries are super super expensive. Like queries are also expensive. Finding all posts that have a term that has a meta that is like X, is an astoundingly expensive/slow query. Writing this out as a custom SQL query is the ...


3

You're missing the tax_query key, and it needs to be a nested array: $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'terms' => $cat_id, 'field' => 'term_id', ), ), ); Check the documentation


3

Try this way: $args = array( 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish' ); if ( isset( $_POST['typefilter'] ) && $_POST['typefilter'] !== '' ) { $args['post_type'] = 'post_type_x'; $args['tax_query'][0]['taxonomy'] = 'type_emp'; $args['tax_query'][0]['field'] = 'id'...


3

I noticed that siteurl.com/series does not work I get my 404 page This is the correct behaviour. There is no content to display at this URL in WordPress. You need to provide a specific term so that WordPress can retrieve posts with that term. Notice that in a fresh install of WordPress siteurl.com/category/ returns a 404, even if you have categories. ...


2

For those who like me were stuck with this issue, I found something useful. I used the priority system function kia_no_child_taxonomies( $query ) { if( is_tax() ): $tax_obj = $query->get_queried_object(); $tax_query = array( 'taxonomy' => $tax_obj->taxonomy, 'field' => 'slug', 'terms' => $...


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

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

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

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/


2

Try the following code: $taxonomy_name = 'listing_category'; $queried_object = get_queried_object(); $term_id = $queried_object->term_id; $termchildren = get_terms( $taxonomy_name, array( 'parent' => $term_id, 'hide_empty' => false ) ); echo '<ul>'; foreach ( $termchildren as $child ) { echo '<li><a href="' . ...


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.


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