Specify number of posts in my ‘tax_query’

Never user query_posts, under any circumstances. Use WP_Query instead, which is how query_posts works internally, but without the trickery and downsides.

You’ll also find that the WP_Query documentation gives you explanations for every parameter, including what you are trying to do:

posts_per_page (int) – number of post to show per page (available with Version 2.1, replaced showposts parameter). Use
'posts_per_page'=>-1 to show all posts (the ‘offset‘ parameter is
ignored with a -1 value). Set the ‘paged’ parameter if pagination is
off after using this parameter. Note: if the query is in a feed,
wordpress overwrites this parameter with the stored ‘posts_per_rss
option. To reimpose the limit, try using the ‘post_limits‘ filter, or
filter ‘pre_option_posts_per_rss‘ and return -1

Including an example:

Show x Posts per page

Display 3 posts per page:

$query = new WP_Query( 'posts_per_page=3' );

or as i would put it:

$args = array(
    'posts_per_page' => 3
);
$query = new WP_Query( $args );

if ( $query->have_posts() ) {
    while( $query->have_posts() ) {
        $query->the_post();
        // display the post
    }
}

Notice how the main loop is the same as when using query_posts, only I’ve added $query-> to the beginning of have_posts and the_post?

You can now modify the parameters to add in your tax query

$args = array(
    'posts_per_page' => 3,
    'tax_query' => array(
        ...etc
    )
);

http://codex.wordpress.org/Class_Reference/WP_Query

Leave a Comment