There is a lot you can do with WordPress regarding searching your blog. You can use the built-in search capabilities, replace it with a search from Google or Yahoo (or whoever), or use an awesome WordPress Plugin called Search Everything to really get full advantage of searching your blog.
Let me explain what and how the built-in search function works with WordPress, for those left confused and frustrated as I was.
How WordPress Search Works
When you search in your WordPress blog, your search results are listed chronologically. Not by “most likely”, “most popular”, “most frequent use of the phrase”, or even alphabetically, just by date. And the chronological order runs from most recent to oldest. If the most likely post to provide the information the user is searching for is older, they will have to scroll towards the end of the list to find the most likely candidate for information. What are the odds they will, huh? This frustrates me no end.
Another frustration with WordPress searching is that it only searches posts. It does not search comments nor Pages. Only post content.
Another thing happens internally that the user never sees, but you, the administrator and/or Theme designer, need to know about. By default, there is a hierarchy to the order of which template is used for which request. A Theme may, or may not, have these optional template files to generate specific web pages, page elements, and looks. In the case of search, when the user clicks the SEARCH button, WordPress looks for a search.php template file. If it doesn’t find it, it will generate the search on the index.php template file.
You can see examples of my main website’s custom index.php page and custom search.php page to get a feel for how these can be customized. The index page features huge excerpts and graphics, while the search results excerpts are shorter, but look similar in design.
A Theme doesn’t have to have a custom search template page, but if they do, it allows customization of how the search results look and feel. Nothing has to be changed within the rest of the templates in order for a custom search template to be added. If you want to add a custom search template, simply copy the search.php template file from another WordPress Theme, or make a copy of the index.php template file and rename it search.php, then style it to match whatever you want your custom search page to look like. No special coding is required. WordPress will automatically find it next time you go to search. Hopefully.
For more information on customizing or creating your own search page, see Creating a Search Page in the WordPress Codex, the online manual for WordPress users, designers, and developers.
Replacing the WordPress Search
To replace the built-in WordPress search functions with a search engine search function, simply sign up and get the XHTML codes for the search engines search function and edit the searchform.php to remove the built-in PHP search functions and replace them with your new code. The WordPress code looks approximately like this:
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div class="searchinput"><input type="text"
class="inputbox" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" class="button" value="Search" />
</div>
</form>
Be sure and test the search engine search functions thoroughly, and style the search engine search to match the look of your WordPress Theme, if necessary. Some search engine functions will allow you to specify a search results page, so if you can, why not make the search results look like your WordPress Theme by generating them on a search.php template file to match the overall look.
The Search Everything WordPress Plugin - Easy Search Expansion
To get around the limits of the WordPress search functions, without replacing it with a search engine search form, the Search Everything WordPress Plugin expands the search results to include comments and Pages, though currently it also returns only chronological results, from most recent to oldest posts.
To install Search Everything, upload the plugin to your wp-content/plugins folder and activate it through your Plugins Administration Panel. That’s it. It works. If you have messed around with your searchform.php template file, you may encounter problems, so check through the comments on the Search Everything WordPress Plugin page for more help, or ask.
Site Search Tags: wordpress, search, plugins, searchform, search.php, index.php, search+engine, search+everything, wordpress+plugins, wordpress+search, custom, customization, search+results
Copyright Lorelle VanFossen











32 Comments
Nice article Lorelle. I still find the search insufficient because WP allows you to do many more things by its functionality. But the search is not up there yet, e.g., I will not be able to search in any data that I create which is not wrapped in WP posts. It currently does not search through excerpt of posts or the other custom fields. While changes can be made to make WP search everything, it depends more on the types in the MySQL database. It would be more flexible and efficient, if it is built into WP design. We can then even have something like an Advanced Search or a filtering process.
One odd thing I have noticed with the search on WordPress.com is it also searches the html tags. If I search for the word strong, I get every post that I have made a word bold in. ()
Wow! I hadn’t noticed that one. Yikes. Though it is neat if you are searching for a specific tag.
Do other searches ignore HTML?
I thought your article was great, this was just the information I was looking for.
Hi
Would you mind posting or emailing your search.php file please? I want to see how you created the excerpts and the block text thing next to each search result.
Thanks
Everton
I explained how to do this in Designing Themes for WordPressMU - Fill in All The Details. Just change
the_content()tothe_excerpt()in thesearch.phptemplate file. I put that section in a specific CSS class and added the border to make it look distinctive when viewed on the front page, search, and category results. Nothing fancy. You can find more details in WordPress Codex - Creating a Search Page.I will be addressing some more specifics about creating a custom search, category, author, and other template files in the next month. Stay tuned.
Hello!
You said that “Some search engine functions will allow you to specify a search results page”. Can you give some examples?
Thank you.
You’ll have to check with the various search engines services, like Google Search or Yahoo Search, and find out how they allow you incorporate their search functions within your WordPress Theme. I may be doing that in the next month, and I’ll report on this then.
Does anyone know exactly where the code for the search is? I’m looking for the code that actually does the MySQL fulltext search for the posts. I’ve found the searchform.php file which spits out the search input field and the button. I’ve also found search.php which is the template for displaying the search results. But, I’m looking for the actual php/mysql code that does the searching. Thanks!
Replacing the WordPress Search
the default action is 1) bloginfo(’home’);
and that you suggest is 2) $_SERVER['PHP_SELF']
what is the difference?
Can you to do an example?
I ask this because the adefault action really isn’t a
file.php but only a folder so I not understand how it work.
what is the file that treat the variable s;
identical for your suggest (..PHP_SELF), the file is the same of the form, but if so you can to do examples of code for treat the datas
Ah good catch. I posted the customized PHP code from an old default WordPress Theme version. I’ll change it to the new, and more appropriate one.
As the instructions say, sign up for a new search engine searching service and you will be given the code to use and search for the above code and replace it with your new code.
Thanks for the catch. See Creating a Search Page in the WordPress Codex for more information on the search functions. As for your answer, that was the old method, and this is the new, replacing PHP function with WordPress template tags, a much more powerful usage. The result is basically the same.
Creating a Search Page at the end reuse the searchform.php;
but if I want really a different search engine type:
to do a search smilar:
search category and custom field;
or search word 1 and 2 and 3 (not exactly phrase but all the words) etc…;
any ideas
Do you know where the actual function to search is performed? I want to alter the SQL consult but can’t find it.
I don’t understand your question. Do you want to do a search and replace within the database? Or improve the search function on a blog?
Hello Lorelle! … Your post is really interesting.. but I have been trying to find (with no luck.. maybe you know about this) what is the algorithm used by the WordPress Search System… also.. where I can find its search function?.. does it have the capability to order the results by relevance?…if it has it.. how does it make this relevancy ranking?… I have checked the DB and it doesn’t create any search-related table…
thanks for your response in advance..
Hmm, the best I can recommend right now is checking through the various WordPress Plugins listed here and in Helping WordPress Search With WordPress Plugins. And for the real answer, ask Mark Jaquith.
When I use the sidebar widget search it adds a break before the search button. Why does it not use the searchform.php and how can I change this?
This is one that you will have to ask on the WordPress Support Forums. I’m not familiar with the search widgets and how they work. Yet.
Thank you so much for posting this Lorelle. I have had a lot of trouble with my WP search. Actually it doesn’t return any results for anything I search for.
When I build themes I do it on another dev site, and the searches work fine. But when i bring that theme into another existing site and start using the theme, the search doesn’t work. I have had this happen on 3 or 4 different themes.
i thought that maybe i had tweaked something a long time ago that inhibited it from working so I downloaded the newest WP (2.3.2?) and re-uploaded everything and then added in my theme again to get a fresh start, but the search still isn’t returning any results.
I am going to try your suggestion for the “search everything” plugin to see if that will help.
if by chance you might know why I’m not getting any results I’d love to hear about it. But at least your article gives me hope.
Thanks
@ Drew Stauffer:
I believe there are some newer search Plugins to try, so look around if that one doesn’t work. The next version of WordPress is slated to have improvements for searching both pages and posts.
I replaced my search with a Google Custom Search engine for a while…
The unfortunate thing was it didn’t work well with ignoring specific posts… I didn’t want to return tag pages, and archives in the results.
One nice feature was it would return results based on comments.
My default wordpress search doesn’t work, I’ve tried many plugins and always get the same result … “No posts found. Try a different search?”. Can anybody help me please? I’ve been through the wordpress support forum many times and can’t find anything that would help.
@ Jaka:
I recommend you try a different WordPress Theme. If the search works, the problem is with the Theme. If it doesn’t work, do a total clean reinstallation of WordPress (backup everything first, delete database, remove everything from the server. Then install.) and see if it works then.
If it doesn’t, consider checking with your web host as there may be some glitch on their end, though unlikely, and then keep asking on the WordPress Support Forum as they are your ONLY source for such help. Plugins aren’t the answer.
I wuse UTW it makes links to the search, but uses blah-blah instead of spacing or + signs. the search hates this. i want to add [code]$wp_query = str_replace(”-”, ” “, $wp_query);[/code] before the search is kicked off. Do you by chance know where I could place that code? where is the actual file that runs the search function?
Thanks!
Quince Wyss
@ Quince Wyss:
The Ultimate Tag Warrior WordPress Plugin is no longer supported. If you are using it on your blog, that means you have not upgraded your version of WordPress. If you have not upgraded, you have been ignoring the very publicized mandatory security upgrades. WordPress blogs not upgraded have been hacked as trouble makers are seeking out those versions.
Upgrade immediately. The latest version of WordPress includes tagging and has an import feature for UTW. There are numerous Plugins, some by the same author, for the new native tags.
Lorelle,
Thank you! This indeed was exactly what I was looking for. I’m seeing that only post content is searchable. I can search for and find categories, BUT if I search for Uncategorized I get no hits even though I have several. Now that I think about it though, when I checked out the database, there were to taxonomies. I wonder if Uncategorized and my other categories were of such that the search only hits one taxonomy? Hmm. Well, at least I have an idea of the scope of the search, and no longer worried that it’s broken. I just had to fix a broken theme that I like but gave a 404 page not found whenever you click the Search button. With your info, I can move on to other tasks and have faith the search works as it was coded for.
Jason
@ Jason Smith:
If you are looking for posts within your “uncategorized” category, use the Manage Posts panel and set it to filter posts by category. That will show you everything in that category. Edit each one and put them in their right category.
Always glad to help.
Can you give me some feedback as to how to get the search posts function working in the admin section?
@ Jeff:
No. It works for me. Please try the WordPress Support Forum for more assistance.
Any clue on how to change the number of results in search page? Af far as I know it obeys to global post per page configuration.
Thx
@ maddler:
These articles might helps: Super Loop: Exclude Specific Categories and Display any Number of Posts and Custom Query String Reloaded for WordPress 2.3 with tag support.
5 Trackbacks/Pingbacks
[...] Understanding, and Fixing, WordPress Search (tags: wordpress search weblog) [...]
[...] Understanding, and Fixing, WordPress Search [...]
[...] those battling the challenges of providing a decent search function on your WordPress blogs, the hunt for the ideal WordPress search is still on. It has improved, but so far, I haven’t found a perfect search WordPress [...]
[...] now that that thinking was rather narrow. Lorelle Van Fossen has a neat post on why and how, on a WordPress site, you would think about replacing the default tool with a third party search tool (such as, but not [...]
[...] Gracias | Lorelle [...]
Post a Comment