Title: Query custom taxonomy posts
Last modified: August 19, 2016

---

# Query custom taxonomy posts

 *  [Stef Verbeeck](https://wordpress.org/support/users/twizted/)
 * (@twizted)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/query-custom-taxonomy-posts/)
 * Hi all,
 * I’m building a website that has a portfolio full of project references, using
   the custom post type “clients”.
 * Using a “type-clients.php” template file and following code I’m able to show 
   all these clients and have them refer to their respective single post version
   using a “single-client.php”.
 * `<?php query_posts('posts_per_page=50&post_type=clients'); ?>`
 * Works like a charm. For these clients however, I have provided a range of “services”
   as a custom taxonomy, used to display which services were used for a specific
   client. I managed to list the services for a client using the following code,
   which actually shows the selected services for that client and makes them clickable.
 * `<?php echo cc_get_the_term_list($post->ID, ‘services’, ‘ ‘, ‘, ‘, ”, 0); ?>’
 * When a link for such a service is clicked, I would like to show all other clients
   that used this service. If I click the link, the page mysite.com/services/_selected-
   service_ is loaded using my “taxonomy-services.php” template, but it shows ALL
   clients instead of only those for the _“selected-service”_.
 * What query do I need to put in my template to make sure only the clients that
   belong to a certain service are shown? I want to do the same as with old-fashioned
   categories, so that site.com/category-name only shows posts for that specific
   category in the url.
 * Thanks in advance for any help.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Stef Verbeeck](https://wordpress.org/support/users/twizted/)
 * (@twizted)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/query-custom-taxonomy-posts/#post-1866920)
 * I tried this:
 *     ```
       <?php
       query_posts( array('taxonomy' => 'services', 'posts_per_page' => 50) ); ?>
       ```
   
 * Butt it didn’t work. All it does is display my 50 latest posts in the classic‘
   posts’ type. No clients, not belonging to any services specified in the url. 
   🙁
 *  Thread Starter [Stef Verbeeck](https://wordpress.org/support/users/twizted/)
 * (@twizted)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/query-custom-taxonomy-posts/#post-1866922)
 * Okay, for those who encounter the same problem and want to display the posts 
   within a custom taxonomy like you display the posts within a classic category,
   here are the two steps:
    1. create a template called “taxonomy-xxx.php”, where xxx is the custom taxonomy
       name
    2. use this code: <?php $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var(‘
       taxonomy’ ) ); ?> instead of query_posts to show the posts for the selected 
       taxonomy
 * Thanks to [Monday By Noon](http://mondaybynoon.com/2010/09/06/wordpress-archive-pages-taxonomy)
   for ending my day-long quest and answering a question which should NOT be so 
   hard to find an answer to imho…

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Query custom taxonomy posts’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [Stef Verbeeck](https://wordpress.org/support/users/twizted/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/query-custom-taxonomy-posts/#post-1866922)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
