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' => ?
);
-1 is your answer! Look for
posts_per_page
here.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.
Or alternatively you can pass
WP_Query
(which is whatquery_posts
uses) thenopaging
argument, which basically does the same thing..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.. 😉
From your child themes functions file:
Using Ricardo’s with some modification:
This will dramatically increase the query time by only querying against the ID row and avoiding updating term and meta cache.
The right answer for your issue is
'posts_per_page' => -1
because-1
will return unlimited posts per page As the others users answer.I just want to add an add-on to this Q/A,
If you want to get the number of posts per page from the reading setting on WordPress Administration Panel you have to call the
get_option()
function and passposts_per_page
as a string to it.I hope this answer will help someone as it help me. Happy Coding Stackexchange Users
Or..