我有一个以前从未发生过的情况。我的搜索。php文件没有生成结果,它只是在所有帖子中循环,尽管url是正确的Domain\\u name/?s=键
这是搜索表单。php代码:
<form action="<?php bloginfo(\'url\'); ?>" id="search-form" method="get">
<div class="form-group">
<input type="text" name="s" id="search-control" class="form-control" placeholder="ادخل كلمات البحث هنا">
</div>
<div class="form-group">
<input type="submit" class="btn btn-default" value="ابدأ البحث">
</div>
</form>
这是搜索结果。php代码:
<?php get_header(); ?>
<section id="main" class="row">
<!--SIDEBAR-->
<div class="col-md-4" id="sidebar">
<?php get_sidebar(); ?>
</div>
<!--MAIN-->
<div class="col-md-8">
<div id="blog-intro" >
<?php $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1; ?>
<?php if ( have_posts() ): ?>
<h2>نتــائج البحث \'<?php echo get_search_query(); /*global $wp_query; $wp_query->set(\'s\',$_GET[\'s\']); print_r($wp_query);*/ ?>\'</h2>
</div>
<div id="posts">
<?php while(have_posts()): the_post(); ?>
<div class="latestPostSingle row">
<div class="latestPostContent col-md-7">
<h5><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h5>
<div class="author"><p class="by"><?php the_author_posts_link(); ?></p></div>
<p><?php the_excerpt(); ?></p>
</div>
<div class="imageLatestPost col-md-5">
<?php
if(has_post_thumbnail()){
the_post_thumbnail(\'cat\');
}else{
?>
<img src="<?php echo IMAGES ?>logo_sm.png" />
<?php
}
?>
<p class="post-info">
<span class="fa-comments"></span> <?php comments_number(); ?> 
<span class="fa-calendar"></span>
<span><?php the_time(\'j\') ?></span>
<span><?php echo the_time(\'M\') ?></span>
<span><?php the_time(\'Y\') ?></span>
 
</p>
</div>
</div>
<hr>
<?php endwhile; ?>
<div id="paginate">
<?php my_pagination(); ?>
</div>
<?php else: ?>
<h3>لا يوجد ما يطابق بحثك</h3>
<?php endif;wp_reset_query(); ?>
</div>
</div>
</section>
<?php get_footer(); ?>
注:如果有任何变化,该网站将使用阿拉伯语。
最合适的回答,由SO网友:kisabelle 整理而成
尝试将以下代码添加到搜索的顶部。get\\u header()调用下面的php模板:
<?php
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array();
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
$search = new WP_Query($search_query);
?>