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 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' => ?
    );
share|improve this question
    
-1 is my rating of this question and ironically also the answer you are looking for :) no offense but your Q doesn't show much research effort... –  Michal Mau Dec 11 '11 at 17:24
2  
I've been Googling for awhile and searching the WP codex, but I just can't find a direct answer to this simple question. I believe my question is worded clearly with example code, and what my attempt was (setting a high value for the argument). I'm not a WP expert, so thats why I came here to ask the question. Even providing answers to questions that seem trivial to you are helpful in growing these Stack Exchange communities. I personally love seeing a Stack Overflow link in my search results, as opposed to a link to a crappy forum. –  Banjer Dec 11 '11 at 17:50
    
Also, thanks for the answer. You should post it as an answer and not a comment, so I can accept it. –  Banjer Dec 11 '11 at 17:51
    
I've got your point and I do appreciate your effort in writing the question. I also agree that non-expert questions can prove themselves valuable in this community. On the other hand too many of such questions can discourage some experts from getting involved here. It's all about some kind of balance I guess. Anyway I'm a big up-voter so I'm looking forward to your next questions :) Have a great time here on WPSE. –  Michal Mau Dec 11 '11 at 18:15
    
PS: you also want to replace type for post_type (or remove this line altogether). I will edit both the Rutwick's answer and your question to prevent somebody from copy-pasting this little mistake. –  Michal Mau Dec 11 '11 at 18:20

3 Answers 3

up vote 14 down vote accepted

-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
);
share|improve this answer
    
Thanks Rutwick! –  Banjer Dec 11 '11 at 17:53
    
You're welcome! –  Rutwick Gangurde Dec 11 '11 at 19:04

Or alternatively you can pass WP_Query(which is what query_posts uses) the nopaging argument, which basically does the same thing..

$args = array(
    'nopaging' => true
    // Your other args, etc..
);

It will do exactly the same, but if you have to look back at it later and can't remember what you were doing, i personally feel it will be more clear to you, what it is you were intending with that parameter inside the args array.

As i mentioned however, they'll both actually achieve the same.

Can't hurt to have more than one approach, and it's always nice to share what you know, suffice to say that's the reason for my answer, despite you already having a sufficient one.. ;)

share|improve this answer

From your child themes functions file:

add_action( 'pre_get_posts', 'wpsites_no_limit_posts' );

function wpsites_no_limit_posts( $query ) {

if( $query->is_main_query() && !is_admin() && is_home() ) {

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

    }

}
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.