Change Number Of Search Results In Wordpress

Wordpress allows administrators to change the number of posts that are printed out on a page at once on the page Settings - Reading. However, this also has an impact on the number of search results that Wordpress will display. In order to keep the size of the home page down many Wordpress admins will reduce the number of articles to two or three. This can instantly make search results with only a few results reach many pages.

To get around this you will need a template called search.php, this is the template that Wordpress will use when printing out the search results. Towards the top of this file (anywhere above The Loop) add the following code.

<?php query_posts($query_string . '&showposts=10'); ?>

The $query_string variable is the currently used query string that generated the search results. Just set the value of the showposts variable to be the number of posts you want to display in the search results.

Comments

Normally I would not post a comment, but you've put together a nice post here and I wanted to say thank you.
Permalink
Thanks for the post. If you don't mind my asking, what WP theme are you using? Is it available Free or is it a custom design? Thanks.
Permalink

You're missing an ampersand:

Permalink
Hmm... Wordpress seems to have eaten your code there. Never mind, I think I see where the ampersand was missing from. Thanks for pointing that out :)
Name
Philip Norton
Permalink
thanks..i search long and hard for this extremely simple code :)
Permalink
Thanks! Exactly what I was looking for! It is a little confusing that you can put the code anywhere near the top and that you have to put in several different files that are not the same from theme to theme. But it works! :)
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.