I've been trying for hours if not a day to try and get my custom search.php and searchform.php to work and still no success. I've read a lot on these two templates and still no success.

Here is my search.php:

<div class="post-wrap">
    <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
        <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
        <?php the_excerpt(); ?>
    <?php endwhile; else: ?>
        <p>Woops There is no post yet</p>
    <?php endif; ?> 
</div><!-- /.social-media-posts -->

Here is my searchform.php:

<form action="<?php echo home_url( '/' ); ?>" id="searchform" class="search-form" method="get" role="search">
    <input type="text" id="s" placeholder="Search" class="search-field">
    <input type="submit" value="&#xf002;" id="searchsubmit" class="search-submit">
    <a class="search-close" href="#"><i class="fa fa-times-circle"></i></a>

And finally, this is what I use to call my searchform.php in my navigation template:

<?php get_searchform(); ?>

Still nothing works, i'm getting a little discouraged. I would appreciate any help. Thanks!


It looks like you aren't actually grabbing the search query in your form. You need to include value="<?php the_search_query(); ?>" in your input field.

Here is a link to the docs for the search form.

I think what you're looking for is under the 'Theme Form' heading.


You are missing the name attribute. you just need to add it to your input field like this

<input type="text" id="s" name="s" placeholder="Search" class="search-field">

Any input field is meant to take data for query, the name attribute is mandatory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.