Title: Multiple taxonomies
Last modified: August 20, 2016

---

# Multiple taxonomies

 *  Resolved [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/)
 * Please can someone help I’m totally confused. I need to list posts with multiple
   taxonomies ie.
 * List custom posts of ‘Therapists’, by taxonomies of ‘location’, and by ‘therapy’.
 * arrghh… Please help.
 *     ```
       $args=array(
        'post_type' => 'therapist',
        'therapies' => 'acupressure',
        'location' => 'bristol',
        'post_status' => 'publish',
        );
   
       $my_query = null;
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
       while ($my_query->have_posts()) : $my_query->the_post();
       ```
   
 * do something…

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/multiple-taxonomies/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/multiple-taxonomies/page/2/?output_format=md)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614671)
 * try it with a tax_query: [http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters](http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters)
 * something like this:
 *     ```
       $args = array(
         'post_type' => 'therapist',
         'post_status' => 'publish',
         'tax_query' => array(
   
       		array(
       			'taxonomy' => 'therapies',
       			'field' => 'slug',
       			'terms' => array( 'acupressure' )
       		),
       		array(
       			'taxonomy' => 'location',
       			'field' => 'slug',
       			'terms' => array( 'bristol' )
       		)
       	)
       );
   
       $my_query = new WP_Query( $args );
       ```
   
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614717)
 * And relax…. thank you keesiemeijer. Seriously appreciated.
 * Got myself in a serious muddle with taxonomies, I still am but I can see a bit
   of light now.
 * Sorry last question, is there a way for it to dynamically get the current taxonomy
   of ‘therapies’ itself. I’m showing it on a post that’s already been tagged with
   the taxonomy of ‘acupressure’.
 * ie. can get the current taxonomy for ‘therapy’ itself?
 * Thanks.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614728)
 * You can get the current category with this:
 *     ```
       $current_cat = get_query_var('cat'); // category ID
       $current_cat_slug = get_query_var('category_name'); // category slug (only on category page)
       ```
   
 * or maybe this with custom taxonomies:
 *     ```
       // get queried object
       $object = get_queried_object();
       if($object->taxonomy == 'therapy' ) {
       $current_tax_term_slug = $object->slug; // term slug
       $current_tax_term_id = $object->term_id; // term ID
       }
       ```
   
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614748)
 * Hmmm… Thanks for your help but I’m Sorry I’m still struggling.
 * How would I get it in the array, such as:
 *     ```
       array(
        'taxonomy' => 'therapies',
        'field' => 'slug',
        'terms' => $object->slug
       ),
       ```
   
 * Perhaps more worryingly if I echo the ‘$current_tax_term_id’ elsewhere on the
   post i get nothing.
 * I’ve registered the taxonomy ‘therapies’ under my custom post type of ‘therapists’.
   All seems to work, however I’ve also allowed the taxonomy ‘therapies’ to be under
   the standard wordpress ‘post’ type.
 * So I’ve then created a standard post called ‘Acupressure’ and tagged it as ‘acupressure’
   in the taxonomy of ‘therapies’. So why does it not echo it’s taxonomy term?
 * I’m so confused 🙁
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614760)
 * > I’m showing it on a post that’s already been tagged with the taxonomy of ‘acupressure’.
 * On what template file are you using this? Are you using this on a archive template
   or single.php?
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614895)
 * Hi, it’s on single.php
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614899)
 * My mistake. On single.php $object = get_queried_object(); is not a taxonomy object
   but a post object. You can check if the post on single.php has any terms of the“
   therapies” taxonomy with this:
 *     ```
       $terms = wp_get_post_terms( $post->ID, 'therapies' );
       if($terms){
       // post has therapies terms attached
       }
       ```
   
 * [http://codex.wordpress.org/Function_Reference/wp_get_post_terms](http://codex.wordpress.org/Function_Reference/wp_get_post_terms)
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614900)
 * Ahhh… makes sense. Thankyou. Sorry for not fully explaining, the current template
   didn’t occur to me. I’m now so close.
 * If i print_r that i get:
 * Array ( [0] => stdClass Object ( [term_id] => 6 [name] => Acupressure [slug] 
   => acupressure [term_group] => 0 [term_taxonomy_id] => 12 [taxonomy] => therapies[
   description] => [parent] => 0 [count] => 2 ) )
 * Which i encouraging as it’s picking up the term.
 * All i need to do now is get that term in your above query
 *     ```
       $args = array(
         'post_type' => 'therapist',
         'post_status' => 'publish',
         'tax_query' => array(
       		array(
       			'taxonomy' => 'therapies',
       			'field' => 'slug',
       			'terms' => // get the current term name
       		),
       		array(
       			'taxonomy' => 'location',
       			'field' => 'slug',
       			'terms' => array( 'bristol' )
       		)
       	)
       );
   
       $my_query = new WP_Query( $args );
       ```
   
 * Thanks for helping – i can finally see the end.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614901)
 * try it with this: [http://pastebin.com/riUCiCm0](http://pastebin.com/riUCiCm0)
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614902)
 * Thanks. I can see that’s exactly what i need but unfortunately it throws up an
   error:
 * Parse error: syntax error, unexpected ‘=’, expecting ‘&’ or T_STRING or T_VARIABLE
   or ‘$’ in /../single.php on line 51
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614903)
 * Oops, change this:
 *     ```
       foreach ($therapy_terms as => $term){
       ```
   
 * to this:
 *     ```
       foreach ($therapy_terms as $term){
       ```
   
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614905)
 * Aw.. so close, I can see why it would work but it’s now displaying nothing. No
   errors all’s fine but just not outputting the name.
 * [http://pastebin.com/uX3tXeNq](http://pastebin.com/uX3tXeNq)
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614907)
 * I need more coffee. Another mistake.
    change this:
 *     ```
       foreach ($therapy_terms as $term){
       ```
   
 * to this:
 *     ```
       foreach ($terms as $term){
       ```
   
 *  Thread Starter [formica](https://wordpress.org/support/users/formica/)
 * (@formica)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614909)
 * Holy Mother of God!
 * Even minus some caffeine you’re an unfettered genius!
 * I can’t thank you enough.
 * Thankyou thankyou and thankyou.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/multiple-taxonomies/#post-2614910)
 * You’re welcome. Glad you got it resolved.

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/multiple-taxonomies/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/multiple-taxonomies/page/2/?output_format=md)

The topic ‘Multiple taxonomies’ is closed to new replies.

## Tags

 * [multiple](https://wordpress.org/support/topic-tag/multiple/)
 * [taxonomies](https://wordpress.org/support/topic-tag/taxonomies/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 16 replies
 * 3 participants
 * Last reply from: [Deepak Rajpal](https://wordpress.org/support/users/deepakrajpal/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/multiple-taxonomies/page/2/#post-2615085)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
