Update 案件已结案。我忘了我的函数中有kill函数。php将附件、搜索、作者、每日存档页面重定向到主页。删除了用于搜索的部件,效果良好。
很抱歉,感谢您的时间和帮助:)
我在wordpress中有一个简单的搜索表单
<form role="search" method="get" class="search-form" action="<?php echo home_url( \'/\' ); ?>">
  <label>
   <input type="search" class="search-field" placeholder="what are you looking for?" value="" name="s" title="enter search" />
  </label>
  <input type="submit" class="btn search-submit" value="Search" />
</form>
 提交表单后,它会重定向到主页。我想把动作改成echo
home_url( \'/search.php\' ); 但我得到了404。
我已经找到了。php完成。代码为
  <?php if ( have_posts() ) : ?>
            <header class="page-header">
                <h1 class="page-title"><?php printf( __( \'Search Results for: %s\'), \'<span>\' . get_search_query() . \'</span>\' ); ?></h1>
            </header>
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( \'content\'); ?>
            <?php endwhile; ?>
        <?php else : ?>
        <p>no results</p>
        <?php endif; ?>
 
                    最合适的回答,由SO网友:Dariusz 整理而成
                    我在我的函数中忘记了这一点。php我有一个kill函数,可以重定向到home。php我的搜索。我只需要从下面的函数中删除搜索
/*  Kill attachment, search, author, daily archive pages
------------------------------------------------ */
add_action(\'template_redirect\', \'bwp_template_redirect\');
function bwp_template_redirect()
{
global $wp_query, $post;
if (is_author() || is_attachment() || is_day() || is_search() || is_multi_author() )
{
  wp_redirect(get_option(\'home\'));
  exit;
}
if (is_feed())
{
    $author     = get_query_var(\'author_name\');
    $attachment = get_query_var(\'attachment\');
    $attachment = (empty($attachment)) ? get_query_var(\'attachment_id\') : $attachment;
    $day        = get_query_var(\'day\');
    $search     = get_query_var(\'s\');
    if (!empty($author) || !empty($attachment) || !empty($day) || !empty($search))
    {
        $wp_query->set_404();
        $wp_query->is_feed = false;
    }
  }
}
 
                
                
                SO网友:Sachet Shrestha
                您需要为搜索添加get\\u search\\u form()函数。php
\'。get\\u search\\u query().\');?>
            <?php get_template_part( \'content\'); ?>
        <?php endwhile; ?>
    <?php else : ?>
        <p><?php _e( \'Sorry, but nothing matched your search terms. Please try again with some different keywords.\' ); ?></p>
        <?php
            get_search_form();
    endif;
    ?>