WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to be able to switch back and forth by clicking an anchor tag preferably, between showing a subset of posts and showing all posts, the code I am using is:

query_posts($query_string . '&posts_per_page=-1');


query_posts( array(
'posts_per_page' => 45,
//'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),

(paged isn't working)

Any way to do this? The problem is I need the 45 limit to show by default, and then a show all anchor tag or button that the user can click.

Any help would be much appreciated!

Thanks! Donna

share|improve this question
up vote 1 down vote accepted

You could add a url parameter for posts per page. Something like this:

$pppage = ( get_query_var( 'posts_per_page' ) == 'all' ) ? -1 : 45;
query_posts( array(
    'posts_per_page' => $pppage
) );

then you can set your URL with the parameter posts_per_page=all if you want to show all the posts, if it doesn't find that parameter it will default to 45 posts. You can rewrite this parameter to something like /all/ to show all.

share|improve this answer
Thanks! Would I put that in the functions.php file? – Donna Mar 20 '12 at 13:58
You use it wherever your current query is. You'll probably want to do the rewrite in functions.php though. – mor7ifer Mar 20 '12 at 14:10
OK i'll try it, thanks so much! – Donna Mar 20 '12 at 14:54

Your Answer


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.