WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to display all the search results on the search.php? Actually it is displaying only 10 results (as set in WordPress settings > general).

share|improve this question
up vote 3 down vote accepted

The quick and dirty way to do it would be to use query_posts again, doubling the number of database calls.

<?php if (have_posts()) : ?>
<?php query_posts('showposts=999'); ?>

Better would be to add this to functions.php, altering the original query before it is executed:

function change_wp_search_size($query) {
    if ( $query->is_search ) // Make sure it is a search page
        $query->query_vars['posts_per_page'] = 10; // Change 10 to the number of posts you would like to show

    return $query; // Return our modified query variables
add_filter('pre_get_posts', 'change_wp_search_size'); // Hook our custom function onto the request filter

If you want to show an unlimited amount of posts, use -1.

share|improve this answer
showposts is depreciated, use posts_per_page. In any case the first example will not work - it will ignore the search term and just show the latest 999 posts. You would need to merge it with the current query (see Codex). The second answer is by far the best, and as @WouterB points out, avoids re-querying the database. – Stephen Harris Mar 19 '12 at 12:33
Thanks @Stephen Harris, I copy pasted the first example from a very old blog, and then indeed realized that on a newer website I used the second option. Didn't look into the details. – WouterB Mar 19 '12 at 12:42
Thanks Wouter it works! I also use this code to display number of results global $wp_query; $total_results = $wp_query->found_posts; echo $total_results; and now is always displaying 0. – Andycap Mar 20 '12 at 17:25
Please don't suggest query_posts() even as a "quick and dirty" solution. – s_ha_dum Nov 14 '15 at 14:26

Try http://wordpress.org/extend/plugins/custom-post-limits/ You can set independent post limits/numbers for all kinds of results, i.e. search, category, tag, archives, author, paged, etc., without needing page templates or custom loops.

share|improve this answer
This time I prefer to get the result without a plugin. However, I had already used the one you suggested and it's very useful to customize search results. – Andycap Mar 20 '12 at 17:29

Pretty easy: -1 overrides the limit. Just merge the default query with your custom arguments.

global $wp_query;
        ,array( 'posts_per_page' => -1 )
share|improve this answer
Thanks kaiser, I prefer the other method without doubling the queries. Anyway, this would work as well. – Andycap Mar 20 '12 at 17:27

Your Answer


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.