Loop for custom post types filtered by a taxonomy

I am using the Custom Post Type feature in WordPress 3 to create an Events section for my website. I am able to get this to display by using the relevante template files, but I also want the event listings visible on other pages.

I’ve done this with the normal post types but these are based on category IDs which Custom Post Types don’t have.

Each event has a taxonomy for country and I want to be able to loop through the events and display only events for specific countries so I want to be able to filter that.

I’ve had a look on the Codex and came up with the following but it doesn’t display anything:

    <?php $args = array(
                'post_type'=> 'events',
                'country'    => 'england'
            $the_query = new WP_Query( $args );           
            if ( $the_query->have_posts() ) :

            // The Loop
            while ( $the_query->have_posts() ) : $the_query->the_post();
                echo '<li>';
                echo '</li>';


            // Reset Post Data

Solutions Collecting From Web of "Loop for custom post types filtered by a taxonomy"

I’ve figured out the answer using the WordPress forum. Solution below:

        <?php query_posts( array( 'country' => 'event-england' ) ); ?>
        <?php if( is_tax() ) {
            global $wp_query;
            $term = $wp_query->get_queried_object();
            $title = $term->name;
        }  ?>

        <span class="tax-title"><?php echo($title); ?></span>
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><?php the_excerpt() ?></li>

        <?php endwhile; else: ?>
        <?php endif; ?>

Every taxonomy (built in like ‘tags’, ‘post-formats’, ‘category’, as well as custom) have an ID, so you can get this one as well.

As far as i can see your query should work if you just add the usual if ( $the_query->have_posts() ) : before your loop and endif; after it.