Your problem is the weird code at the top of the page. To understand what’s happening let me state a standard loop in pseudocode:
if we still have posts to process
while we still have posts to process
mark this post as processed and move to the next one
do things with it ( like printing the title and contents
What you have is equivalant to:
mark the first post as processed
if we still have posts to process
while we still have posts to process
mark this post as processed and move to the next one
do things with it ( like printing the title and contents
So if your search result only returns a single result, it will never be shown.
So this is what I recommend you do:
Remove the hocus pocus in your header
Anytime you see anything like this:
<?php
get_header();
the_post();
?>
<?php define('WP_USE_THEMES', false); get_header(); ?>
I want alarm bells to start ringing. That code makes no sense, there’s no reason to misuse WP_USE_THEMES
like that, and it has no place in a theme. the_post
should only be called inside a post loop, not outside, and calling get_header
twice does no good. Call it once and remove the rest.
I have a strong feeling you do not understand what the code does or how it works. That’s okay, nobody else does either, remove it. Anytime you find yourself resorting to such code, or flailing about with random things trying to get stuff to work, stop, and go researching the basics. It will save you time and clear your mind.
Indenting and php tag spam
You have so many potential issues that are easy to spot but hidden in difficult to read code
For example this is a bad sign and a waste of your time to type out:
?>
Each statement should be on its own line, and you should indent consistently. Your posts loop is a prime example of a lack of indenting. Your editor should automatically do this for you, but if it doesn’t I recommend opting for something such as SublimeText or PHPStorm. There are many others out there.
get_template_part
Your misuse of get_header suggests you would benefit enormously from knowledge of how to use get_template_part
.