Customize search page

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?

UPDATE:

Read More

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?

Related posts

Leave a Reply

3 comments

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

    searchform.php

    <div class="search">
        <form method="get" class="search-form" id="search-form" action="<?php bloginfo( 'url' ); ?>/search/">
        <div>
            <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" />
        </div>
        </form>
    </div>
    

    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.

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

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