Display number of posts via adress bar?

when i call this link ;

?s=key&order=ASC

wp display my search query order by ASC.

Read More
?s=key&order=ASC&number=10

how can we display whatever i want to display postnumber like 10 or more ?

is that possible ?

Related posts

Leave a Reply

1 comment

  1. If you’re asking to change the number of posts from 10 to something else, you can do one of the following

    1) Submit the search query as

    ?s=key&order=ASC&posts_per_page=5
    

    You can achieve this by adding hidden fields to the form. Just change the number to whatever you want

    2) Go to Settings > Reading, change the setting there. This will change the setting for all the pages though

    3) Add this to your theme’s functions.php or in a plugin

    add_filter('pre_get_posts', 'change_posts_on_search');
    function change_posts_on_search($query) {
        if($query->is_main_query() && $query->is_search())
            $query->set('posts_per_page', 5); // change the number here
    }
    

    UPDATE IN RESPONSE TO COMMENT

    <form action="<?php echo home_url( '/' ); ?>" method="get">
        <input type="text" name="s" />
        <select name="posts_per_page">
            <option>5</option>
            <option>10</option>
            <option>15</option>
            <option>20</option>
        </select>
        <input type="submit" />
    </form>
    

    This form does that work. Basically it’s same as the first option above. But except for the hidden field, it shows the field to the user allowing for changes.