我正在尝试构建我的搜索结果页面,我正在使用wp\\u query。然而,随着时间的推移,我会搜索一些东西,我所有的帖子都会显示出来,而不仅仅是那些与搜索匹配的帖子。为什么会这样,我该如何解决?
<?php
get_header(); ?>
<?php
$args = array(
\'posts_per_page\' => 4
);
$search_query = new WP_Query( $args );
if ( $search_query->have_posts() ) :
?>
<div class="search-results-search">
<form role="search" method="get" class="search-form-search form-inline-search" action="">
<div class="input-group-search">
<input type="search" value="" name="s" class="input-sm-search search-field-search form-control-search" placeholder="<?php echo $s ?>">
</div>
</form>
</div>
<?php while ( $search_query->have_posts() ) : $search_query->the_post() ?>
<article <?php post_class( \'col-sm-6 col-md-6\' ); ?>>
<?php the_post_thumbnail(\'full\', array(\'class\' => \'medium-front-thumbnail\')); ?>
<div class="front-page-date"><?php echo human_time_diff( get_the_time(\'U\'), current_time(\'timestamp\') ) . \' ago\'; ?></div>
<h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part( \'front-shop-the-post\' ); ?>
<?php get_template_part( \'share-buttons\' ); ?>
<div class="front-comments"><?php comments_popup_link (\'0\', \'1\', \'%\', \'comment-count\', \'none\'); ?></div>
</div>
</article>
<?php endwhile ?>
<?php else : ?>
<h2>Ooops, no posts here!</h2>
<?php endif ?>
<?php
wp_reset_postdata();
get_footer(); ?>