Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

when i call this link ;

?s=key&order=ASC

wp display my search query order by ASC.

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

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

is that possible ?

share|improve this question
    
Could you precise your question ? What do you want to display ? The search results starting at the 10th one ? Or the post that has the id of 10 ? –  Fabien Quatravaux Oct 20 '12 at 0:59
    
@FabienQuatravaux i want to display both. –  Fatih Toprak Oct 20 '12 at 12:12
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
Aggard i'll try than. Thank you. –  Fatih Toprak Oct 20 '12 at 12:12
    
You welcome. BTW, not Aggard :P –  Mridul Aggarwal Oct 20 '12 at 13:07
    
Sorry about that @Mridul Aggarwal by the way, i have another question, how can we add a select option box for this query. when user select 10 i want to display 10 results when he select 20 i want to display 20 resulst ? could you give me an example please. ? –  Fatih Toprak Oct 20 '12 at 16:02
1  
updated the answer –  Mridul Aggarwal Oct 20 '12 at 17:57
    
Thanks you @Mridul I'm grateful. –  Fatih Toprak Oct 20 '12 at 19:12
add comment

Your Answer

 
discard

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.