当在search.php中找不到结果时,wordpress边栏循环将不起作用

当在search.php中找不到结果时,wordpress边栏循环将不起作用,php,wordpress,search,Php,Wordpress,Search,在wordpress in search.php中,我有这个 get_header(); ?> ...html/css <?php if ( have_posts() ) : ?> <?php while (have_posts()) : the_post(); ...loop stuff <?php endwhile; ?> <?php wp_pagenavi(); ?> <?php else : ?> <

在wordpress in search.php中,我有这个

get_header(); ?>
...html/css
 <?php if ( have_posts() ) : ?>   
 <?php while (have_posts()) : the_post(); 
 ...loop stuff
 <?php endwhile; ?>
 <?php wp_pagenavi(); ?>
 <?php else : ?>
 <h3><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'hartyinternational' ); ?></h3>
                    <div class="nothing-found"><?php get_search_form(); ?></div>
    <?php endif; ?>
   <?php wp_reset_query(); ?>
还有一个类似的, 当搜索结果被找到时,这些工作完全正常,但是当没有找到结果时,循环无法加载任何内容,有什么建议吗


这看起来不像是一个循环中有一个循环或类似的情况,我似乎无法找出可能的错误,任何帮助都将非常感谢。

我从我的查询中删除了
if(have_posts()):
,这解决了问题。

侧边栏是否加载,而不加载任何查询?或者根本就没有加载?您是否在侧边栏中添加了一些其他内容,以确保它加载到您的空搜索结果页面上?您好,我删除了
if(Have_posts()):
,这似乎解决了问题,但感谢您的回复。我很高兴您能让它正常工作。
    if ( have_posts() ) :
$counter = 0;

            $the_query =  new WP_Query( array( 'posts_per_page' => 5, 'cat' => 4 ) );
            while ($the_query->have_posts() ) : $the_query->the_post(); 
            $counter++;
            if ( $counter == 1 || $counter == 3 || $counter == 5   ){
            ?>
            <a href="<?php the_permalink(); ?>"><div class="recent-position-single"><?php the_title();  ?></div> </a>
        <?php }
            else {
            ?> <a href="<?php the_permalink(); ?>"><div class="recent-position-single darker-shade"><?php the_title();  ?></div> </a>
        <?php }



            endwhile;
 wp_reset_query();
 endif; 
 wp_reset_postdata(); ?>