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 code below to display posts defined as a custom-post-type and filtered by a custom-taxonomy of 'england'.

I've tried using 'posts_per_page=5' in the query_posts function but this brings up a completely different set of posts from one of my post categories of type 'news'. When I remove the posts-per-page from the query, it returns the listings I want but it defaults to the default 10 set within the Wordpress Settings. How do I override it in the code 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>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

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

            <?php endwhile; else: ?>
            <?php endif; ?>
        </ul>       
share|improve this question
    
have you tried it this way: <?php query_posts( array( 'posts_per_page' => 5, 'country' => 'event-england') ); ?> –  Michael May 24 '11 at 13:48

1 Answer 1

up vote 3 down vote accepted

Something like this is what you need. The Codex page for WP_Query is very helpful

$args = array('post_type' => '<your custom post type name>',
              'posts_per_page' => 5,
               'tax_query' => array(
                                array(
                                  'taxonomy' => '<your custom taxonomy name>',
                                  'field' => 'slug',
                                  'terms' => 'event-england'
                                 )
                           )
         )

$query = new WP_Query($args)
share|improve this answer

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.