posts - Display all search results

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

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

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 edited Nov 14, 2015 at 14:06 user9447 1,7927 gold badges30 silver badges55 bronze badges asked Mar 19, 2012 at 11:53 AndycapAndycap 5852 gold badges9 silver badges22 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

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.

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

Try http://wordpress/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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745282170a4620340.html

相关推荐

  • posts - Display all search results

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

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信