Get all posts for custom taxonomy in WordPress

I’ve been doing a lot of behind-the-scenes stuff over at UltimateVelocity and I want to share one thing that caught me out quite a bit recently.

When getting all the posts associated with a custom taxonomy, you should use this codex example.

<?php
$args = array(
	 'posts_per_page' => 8,
	 'orderby' => 'rand',
	 'post_type' => 'albums',
	 'genre' => 'jazz',
	 'post_status' => 'publish'
);
$show_albums = get_posts( $args );
?>

If you want to return all the posts, simply replace

'posts_per_page' => 8

with

'posts_per_page' => -1

Also, by default, the function only returns 5 posts, if if you omit to specify ‘posts_per_page’, you will see just 5 posts returned and you will be puzzled as to why.