我有一个自定义搜索表单。php和搜索。php在我的主题中。然而,当搜索某个内容时,我看到的只是首页(mysite.com/?s=地址栏中的某个内容)。我使用一个过滤器让Wordpress使用我的自定义搜索表单(不知道为什么它不会使用它)。当我使用不同的主题时,搜索确实有效。
筛选函数中的代码段。php:
function search_form_no_filters() {
  // look for local searchform template
  $search_form_template = locate_template( \'searchform.php\' );
  if ( \'\' !== $search_form_template ) {
    // searchform.php exists, remove all filters
    remove_all_filters(\'get_search_form\');
  }
}
add_action(\'pre_get_search_form\', \'search_form_no_filters\');
 我的搜索表单。php
<form id="searchform" action="<?php echo home_url( \'/\' ); ?>" method="get" role="search">
    <div class="input-group">
        <input id="s" type="text" name="s" class="form-control">
        <span class="input-group-btn">
            <button class="btn" type="button" id="submit">Go</button>
        </span>
    </div>
    <script>
        jQuery(document).ready(function($){
            $(\'#searchform #submit\').on(\'click\', function(){
                $(\'#searchform\').submit();
            }); 
        });
    </script>
</form>
 出于调试目的,我目前使用搜索。来自2144主题的php。
我研究过这个问题,似乎最常见的错误是搜索查询输入字段的名称不是“s”。不过我说得对。
 
                SO网友:Faisal Khurshid
                为什么要使用此筛选代码,WordPress仍将使用searchform。php代码,没有它?
此外,搜索中的循环代码可能存在一些问题。php。第214个主题查找内容-[帖子格式]。php文件。你的主题根中有吗?
get\\u template\\u part(\'content\',get\\u post\\u format());
尝试在搜索中使用此简化循环。php。。。
        <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; endif; ?>