Update Case closed. I forgot I have a kill function in my functions.php with redirects attachment, search, author, daily archive pages to home. Deleted the part for search and works fine.

Sorry for that, and thank you for your time and help :)

I have a simple search form in wordpress

<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
   <input type="search" class="search-field" placeholder="what are you looking for?" value="" name="s" title="enter search" />
  <input type="submit" class="btn search-submit" value="Search" />

After I submit the form it redirects to home page. I was trying to change the action to echo home_url( '/search.php' ); but then I get a 404.

I have got the search.php done. The code is

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

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

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content'); ?>

            <?php endwhile; ?>

        <?php else : ?>

        <p>no results</p>

        <?php endif; ?>

2 Answers 2


I forgot that in my function.php I had a kill function that was redirecting to home.php my search. I just needed to delete search from the function below

/*  Kill attachment, search, author, daily archive pages
------------------------------------------------ */
add_action('template_redirect', 'bwp_template_redirect');
function bwp_template_redirect()
global $wp_query, $post;

if (is_author() || is_attachment() || is_day() || is_search() || is_multi_author() )

if (is_feed())
    $author     = get_query_var('author_name');
    $attachment = get_query_var('attachment');
    $attachment = (empty($attachment)) ? get_query_var('attachment_id') : $attachment;
    $day        = get_query_var('day');
    $search     = get_query_var('s');

    if (!empty($author) || !empty($attachment) || !empty($day) || !empty($search))
        $wp_query->is_feed = false;

Yo need to add get_search_form() function for search.php

' . get_search_query() . '' ); ?>
            <?php get_template_part( 'content'); ?>

        <?php endwhile; ?>

    <?php else : ?>

        <p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.' ); ?></p>


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.