Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>';
                the_title();
                echo '</li>';
            endwhile;

            endif;

            // Reset Post Data
            wp_reset_postdata();
    ?>
share|improve this question
add comment

2 Answers 2

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
add comment
up vote 1 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;
        }  ?>

        <ul>
        <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; ?>
        </ul>
share|improve this answer
add comment

Your Answer

 
discard

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.