posts_per_page no limit

I want to return ALL posts with query_posts. I tried setting posts_per_page to a really high number, but query_posts freaks out and doesn’t return any posts. What is the correct way to query posts without a limit?

$args = array(
    'post_type'      => 'post',
    'cat'            => '22,47,67',
    'orderby'        => 'name',
    'order'          => 'ASC',
    'hide_empty'     => 1,
    'depth'          => 1,
    'posts_per_page' => ?
    );

6

-1 is your answer! Look for posts_per_page here.

$args = array(
'post_type'      => 'post',
'cat'            => '22,47,67',
'orderby'        => 'name',
'order'          => 'ASC',
'hide_empty'     => 1,
'depth'          => 1,
'posts_per_page' => -1
);

Important caveat: This can result in a very huge query that can bring the site down. Do this only if you are sure your database can handle it. Not in public themes or plugins.

Leave a Comment