in wordpress in search.php I have this..
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(); ?>
then I have built my own sidebar with WP_Query loops,
e.g.
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(); ?>
and another similar one,
these work completely fine when search results are found, but when no results are found the loops fail to load any content, any suggestions?
It doesnt seem like a situation where there is a loop within a loop or anything like that, I cant seem to figure out what could be wrong, any help would be great thanks.
I removed
if ( have_posts() ):from my queries and that resolved the issue.