custom query with dynamically changing post per page with pagination

  • Unknown's avatar

    Hi everyone,

    what’s the best way to implement a custom query, where the user can change the posts per page dynamically (via html form) with a working pagination.

    $currentPage = get_query_var('paged');

    $the_query = new WP_Query(
    array('posts_per_page' => $_GET["show"],
    'paged' => $currentPage,
    ));

    The problem is, that when changing the posts_per_page value via html form,
    the currentpage stays the same.

    For example I have 10 posts in total, the page_per_post is 4.
    So I would have 3 pages.
    If the user is on page 3 and changes the page_per_post to 100,
    then the querey will display no posts, because for 100 posts per page there does not exist page 3, only page 1…

    I hope you’ll understand my problem.
    Thank you in advance

  • Hi!

    I am afraid we are unable to help you here. These forums are only for questions related to WordPress.com sites.

    You can post the question on self-hosted WordPress (WordPress.org) forums for help: https://wordpress.org/support/

  • The topic ‘custom query with dynamically changing post per page with pagination’ is closed to new replies.