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.

2 Answers 2


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

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[] = '';

  • completely missunderstood you. i thought two taxonomies, not post types.
    – kaiser
    Commented Mar 10, 2011 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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