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.

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

share|improve this question
add comment

3 Answers

up vote 2 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
1  
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
add comment

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
add comment

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

global $wp_query;
query_posts( 
    wp_parse_args(
         $wp_query->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
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.