Support » Fixing WordPress » Where is the Search code (to use in custom template)?

  • Hi there, thank you for your time!

    I’m experiencing a very annoying problem: I can’t get the built-in WordPress search function to actually work/do its job! It doesen’t find anything, and I’m not really sure it’s even searching. I think it just automatically falls back on the “if/else” statement when there is no search result to display, and displays nothing. (But that’s wrong!)

    (Sad to say I can’t post a URL to the website mentioned since I then would have to take it out of Maintenance Mode, and I don’t think my client would appreciate it … :-))

    No search results no matter what
    I have made a completely custom made template for my whole site, but I just can’t get the search function to actually Search for something. It just ends up saying there was no matching search results etc – even though I make sure to search for both the title words or content words of my posts. I really feel something is missing in either the output of the search results, or in the code function that’s actually gonna do the collecting of information (the search).

    Official Codex tutorial does not do it
    I have followed the steps of (creating a searchpage.php template etc, even though I’m not sure it’s 100% right since I’m not really gripping the “Preserving Search Page Results and Pagination” part).

    I have also created the searchform.php, but still the search doesen’t really do anything. It just re-directs me back to index.php (which does not hold any content-loop since it’s not one of the WP content pages). My code looks like this:

    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <input name="s" value="<?php echo wp_specialchars($s,1); ?>" type="text" id="s" size="18" />
    <input type="submit" id="search_submit" value="Search" /></form>

    But when I also include a direct copy of my “page.php” and rename it to “search.php” I at least get a callback from the search query – but all it’s saying is that nothing could be found. So what the heck is going on, since there’s clearly pages/posts to be found?

    The cry for help
    I somehow feel that some critical element of code output must be missing somewhere. So, can anyone PLEASE write a short (or long :-)) summary of how the affected search code sections should be written inside the different needed php-files (searchpage.php, page.php, search.php?).

    Short story: If you had/have a custom template and needed a search function – what would you need to do (or have done) to make the built-in WordPress search function to work? Maybe not even me outputting loop code at page.php is correct..? Assist me then with a correct one, write it in full 🙂

    Ice creams for everyone! Thank you so much for getting this far, and thanks in advance for any help you might give me!

    Best regards,
    Henrik – Sweden

  • The topic ‘Where is the Search code (to use in custom template)?’ is closed to new replies.