WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I just click search, wordpress takes me to the 404 page. I'd like to just have a search template (maybe a page) that does search. Can anyone help?


I created a custom search page (link), and changed things around in my header file to reflect the custom search page, however now the search is broken. Can you check out the code and help me out?

share|improve this question
If search function is implied but broken then there is likely issue with theme or some other code. You should figure that one before jumping to customization. Which theme are you using? Link to it if publicly available. – Rarst Sep 1 '11 at 20:58
I've customly created the theme at link and I have search.php and no searchform, because the form is hardcoded into the theme (header.php) Does WordPress only use search.php to query posts? What are they technically displayed on? – Josh Allen Sep 1 '11 at 23:26

Check to see that you have a search.php (results page) and searchform.php(code of the search box). could be something wrong with your searchform.php file.

share|improve this answer

You are including some extra arguments in search query. So when you have no text in query, but do have those parameters WordPress gets confused.

Template for search results display is selected according to template hierarchy:

  • search.php
  • index.php

But since you want something a little more complex then generic text search, you might need to create custom search page instead.

share|improve this answer
Then is there any way to include an if that check if the search string is emty and shows custom text? I'd like to include a search form on the page and some descriptive text rather than 'Not Found'. – Josh Allen Sep 2 '11 at 11:03
@Josh Allen I am not completely sure, but the issue seems to be that empty search is not being recognized as search at all. And if it is not recognized, then it won't pick up search.php template that would be a place for such check. As per answer I'd look into creating completely custom search page if complexity is anything but basic. – Rarst Sep 2 '11 at 11:32
up vote 0 down vote accepted

I feel bad for answering my own question on here, but here's what I did.

I created a custom search template, a custom searchform.php and changed my header.php to reflect my custom search page.

What I did is rename the search box names to search instead of s to get around WordPress automatically running search.php and coming up with a 404 error (still not sure why it happened, probably my fault in search.php) and then used a new WP_Query while setting my arguments. While my solution does not provide anything more than a search term, it could be easily implemented to pull other key-value pairs into the arguments array.


<div class="search">
    <form method="get" class="search-form" id="search-form" action="<?php bloginfo( 'url' ); ?>/search/">
        <input class="search-text" type="text" name="search" id="search-text" value="Search this site" />
        <input class="search-submit" type="submit" name="submit" id="search-submit" value="Search" />

search-template.php snippet

$s = wp_specialchars(stripslashes($_GET["search"]), 1);
$search_query = array(
    's' => $s

$search = new WP_Query($search_query);

So essentially s is now search to get around WordPress automatically using search.php.

If anyone has any questions, feel free to post a comment.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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