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 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
share|improve this question
up vote 2 down vote accepted

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; ?>
share|improve this answer

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.

share|improve this answer
I have followed your suggestion but still nothing showing? Please see updated code in my original post. – techcastoni May 24 '11 at 10:20

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.