WordPress keeping posts per page value when paginating

I have a select that allows a user to select the amount of posts shown on a blog listing page. At the moment the select auto-submits its form and the posts_per_page value is updated for the page query on re-load.

global $query_string;
if(isset($_REQUEST['set_posts_per_page']))
    $ppp = $_REQUEST['set_posts_per_page'];
else
    $ppp = 12;
query_posts("{$query_string}&posts_per_page=".$ppp);

Currently generating pagination buttons using standard WordPress functions:

previous_posts_link( '<span class="etc"></span>' );
next_posts_link('<span class="etc"></span>' );

What’s the best way to re-work this so that users can use the pagination and posts_per_page options?

There are several pages like this listing different custom post types that have to work in the same way (if that makes a difference).

Read more here: WordPress keeping posts per page value when paginating

Leave a Reply

Your email address will not be published. Required fields are marked *