WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two custom post types: event and contact:



Both of them uses a custom taxonomy: country

I just created a template named: taxonomy-country.php

But I Need two separated templates, one for events who uses countries and another one for contacts who uses countries. For example, to display all events in United States or all contacts from Costa Rica.

This is my actual code of taxnomy-country.php, but only for events who uses countries.

 * The template for displaying Countries Taxonomy.


$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );


$args = array();

$args['post_type']  = 'event';
$args['taxonomy']   = $term->taxonomy;
$args['term']   = $term->slug;


        <div id="container">
            <div id="content" role="main">

                <h1 class="page-title"><?php
                    printf( __( 'Archives: %s', 'twentyten' ), '<span>' . $term->name . '</span>' );
                    $category_description = category_description();
                    if ( ! empty( $category_description ) )
                        echo '<div class="archive-meta">' . $category_description . '</div>';

                /* Run the loop for the category page to output the posts.
                 * If you want to overload this in a child theme then include a file
                 * called loop-category.php and that will be used instead.
                get_template_part( 'loop', 'category' );

            </div><!-- #content -->
        </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Thanks in advance.

share|improve this question
up vote 3 down vote accepted

You use get_query_var('post_type') to set the post type in your args array

$args['post_type']  = get_query_var('post_type');

and also include the right loop part based on that for example:

if (get_query_var('post_type') == "event"){
   get_template_part( 'loop', 'event' );
   get_template_part( 'loop', 'other' );
share|improve this answer

Have you already look into what comes back from $term-taxonomy?

Try this right before your query:

echo '<pre>';
echo '</pre>';

I don't know exactly the output without trying it now, but i guess it's an array and in this case you could just take the taxonomy you need.

Note: You don't need to specify $args = array(). The conversion to an array already happens when you type $args[] = '';

share|improve this answer
completely missunderstood you. i thought two taxonomies, not post types. – kaiser Mar 10 '11 at 19:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.