Display wordpress search results

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.

Read More

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(); 

?>

Related posts

Leave a Reply

1 comment

  1. The problem is that you don’t have anything in your loop to print the results, i.e.

    <?php while (have_posts()) : the_post(); ?>
      <h1>Search Results</h1>
      <!-- Needs something here -->
    <?php endwhile; ?>
    

    To fix the problem, simple replace <!-- Needs something here --> with the following

    <a href="<?php the_permalink() ?>">
      <h2><?php the_title(); ?></h2>
    </a>
    <p><?php the_excerpt(); ?></p>
    

    You 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.