• 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

    (@twizted)

    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

    (@twizted)

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