我有一个自定义搜索表单。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”。不过我说得对。