Search result is disappearing when I search from the search result in wordpress

I am designing a theme for a job aggregation website (currently I am using default one which is twenty fourteen).

I am facing a problem is that when I search from a category page with proper keywords I get the result. and from the search result page I again search using a term not in the data base it shows nothing found.

Read More

Till this everything properly happening. But if I search once more using a keyword which is not in the data base it shows nothing found and change the category to null. So if I search again with proper keyword the result shows from other categories.

Here is the link to the website

http://alltopjobs.net/country/india

And here is the search.php code

<?php
/**
 * The template for displaying Search Results pages
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */

get_header(); ?>
<?php
if ($_GET['cat'] != '') {
	$posts = query_posts($query_string . '&post_type=post'); // return only posts
} else {
	$posts = query_posts($query_string . '&post_type=page'); // return only posts
}
?>
<?php $category = get_the_category(); ?>
<form  method="get" id="jobsearch" action="<?php bloginfo('home'); ?>">
	<input type="text" placeholder="Search any jobs here..." required value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
     <input type="hidden" name="cat" value="<?php echo $category[0]->cat_ID; ?>" />
	<button type="submit" id="jobsubmit" value="Search Jobs" />FIND JOBS</button>
</form>

	<section id="primary" class="content-area">
		<div id="content" class="site-content" role="main">

			<?php if ( have_posts() ) : ?>

			<header class="page-header">
				<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyfourteen' ), get_search_query() ); ?></h1>
			</header><!-- .page-header -->

				<?php
					// Start the Loop.
					while ( have_posts() ) : the_post();

						/*
						 * Include the post format-specific template for the content. If you want to
						 * use this in a child theme, then include a file called called content-___.php
						 * (where ___ is the post format) and that will be used instead.
						 */
						get_template_part( 'content', get_post_format() );

					endwhile;
					// Previous/next post navigation.
					twentyfourteen_paging_nav();

				else :
					// If no content, include the "No posts found" template.
					get_template_part( 'content', 'none' );

				endif;
			?>

		</div><!-- #content -->
	</section><!-- #primary -->

No idea how to solve this issue.
Any solution for this problem highly appreciated.
Thank you

Related posts