I’m trying to make a custom search page, by creating all new search.php file, for my wordpress template…so far, so good.
The problem is that when I search for something it doesn’t show any results.
I’m guesing that it has something to do with some php script or something I don’t know.
How can I fix that ?
P.S The function for the number of the results works fine, but there isn’t any results.
Here is the content of search.php
<?php
get_header();
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h1>Search Results</h1>
<?php endwhile; ?>
<?php else : ?>
<?php _e( 'Nothing Found' ); ?>
<?php endif; ?>
<?php
get_footer();
?>
The problem is that you don’t have anything in your loop to print the results, i.e.
To fix the problem, simple replace
<!-- Needs something here -->
with the followingYou also need to move
<h1>Search Results</h1>
to above the loop to stop it from displaying multiple times. It may be best to move it above the if statement if you don’t intend on adding it to your else statement as well.