我正在尝试构建一个自定义搜索结果页面。我遇到的问题是,当我输入搜索词时;如果说“游戏”,它只会返回一个结果,即最新的结果。我的博客设置为一次只显示一篇文章。然而,我发现了一种绕过搜索结果页面的方法,即登录到wp admin->settings->reading->并更改博客页面显示一篇文章,例如10。
然后,当我尝试搜索游戏时,它会返回多个结果(会给我10个)。然而,我不想这样。我希望我的网站博客页面只显示一篇文章,结果页面显示多个结果。我怎样才能着手解决这个问题?
这是我的search.php 看起来像。我创建了一个searchpage.php 我使用PHP来获取search.php 
谢谢!:)
    <!-- SEARCH PAGE -->
    <div id="search-results" class="wrapper" role="search">
<h2> Search Results</h2>
<!-- COUNT RESULTS -->
<div class="results">
    <?php
    /* Search Count */
    $allsearch = &new WP_Query("s=$s&showposts=-1"); 
    $key = wp_specialchars($s, 1);
    $count = $allsearch->post_count; 
    _e(\'\');
    _e(\'"<span class="search-terms">\');
    echo $key;
    _e(\'</span>"\'); 
    _e(\' — found \');
    echo $count . \' \'; 
    _e(\'articles\');
    wp_reset_query(); ?>
</div>
<!-- / COUNT RESULTS -->
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- LIST RESULTS -->
<section>   
    <h3>
        <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to 
        <?php the_title_attribute(); ?>"><?php the_title(); ?></a> - 
        <span class="search-time"><?php the_time(\'F, j, Y\') ?></span>
        </li>
    </h3>
</section>
<!-- / LIST RESULTS -->
<?php endwhile; else: ?>
<!-- 404 SEARCH -->
<div class="404-search">
<?php _e("Oops... We couldn\'t find what you were searching for. Please try again"); ?>
</div>
<!-- / 404 SEARCH -->
<?php endif; ?>
     </div>
     <!-- / SEARCH PAGE -->
 
                    最合适的回答,由SO网友:Max Yudin 整理而成
                    改变
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
 至
<?php if ($allsearch->have_posts()) : ?>
<?php while ($allsearch->have_posts()) : $allsearch->the_post(); ?>
 因为否则您不会使用自定义查询。
看见WP_Query Usage.
同时呼叫wp_reset_query(); 循环之后。
看见wp_reset_query Description.
实际上,你不需要wp_reset_query(); 因为您使用自定义WP_Query 对象,无需重置global $wp_query.