Changing the Number of Search Results Displayed in WordPress

The number of search results displayed in a listing page in WordPress seems to be linked to the Settings > Reading > Blog pages show at most setting in the WordPress dashboard.

This can create a problem, because you likely want to have a greater number of search results displayed on a page than full posts displayed one above another.

If your template has a search.php page they you're in luck.

From your WordPress dashboard, select Appearance > Editor, then under Theme Files select Search Results (search.php). This will open up the search.php code for editing.

Look for the following line;

<?php if (have_posts()) : ?>

and place the following line above it;

<?php query_posts('showposts=20'); ?>

In my template it looked like this;

<div id="content">
<?php query_posts('showposts=20'); ?>
<?php if (have_posts()) : ?>

The number you assign to "showposts=" is, of course, up to you.

Modifying the number of results shown for a Categories listing seems to be a different kettle of fish. For me, as of WordPress 2.9.2, it's linked to the Blog pages show at most setting. Someday I'll figure it out. If you get there first, please leave a comment!

Leave a Reply