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).

3 Answers 3


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.

  • 7
    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. Mar 19, 2012 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, 2012 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, 2012 at 17:25
  • Please don't suggest query_posts() even as a "quick and dirty" solution.
    – s_ha_dum
    Nov 14, 2015 at 14:26
  • To show all posts, as referenced in the question, you can change 10 to -1 $query->query_vars['posts_per_page'] = -1;
    – allicarn
    Jun 1, 2018 at 3:03

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

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

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.

  • 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, 2012 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.