admin管理员组文章数量:1418094
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
).
3 Answers
Reset to default 8The 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.
本文标签: postsDisplay all search results
版权声明:本文标题:posts - Display all search results 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745282169a2651485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论