HomePHP Customizing WordPress Search Results to Sort by Title
Customizing WordPress Search Results to Sort by Title
Sorting search results by post title in WordPress is often useful, if your website needs its entries to be sorted alphabetically. As a quick background, WordPress is the most popular open source, free blogging/CMS platform. However, the default search results are sorted by date, so there is no easy way to sort them alphabetically except to edit the core WordPress search functionally source code.
There are a number of applications for which it would be useful to sort post titles alphabetically. For example, say you use WordPress for a social networking site. With that kind of site, people stop by and register their names. As a result, users need to be able to search for names in the WordPress search box. So the search results need to be sorted alphabetically so that visitors can easily find people's names.
There are countless applications for the ability to sort post titles alphabetically in WordPress. Here's another example: say you use WordPress on an online bookstore. Again, you'll need to alphabetize search results, by book titles and/or author names. As of February 2009, surprisingly enough, no WordPress plug-in has been developed to provide this feature.
In fact, one of the best ways to apply this feature is to work with the “Search Everything” plug-in. You can read more about this in: http://wordpress.org/extend/plugins/search-everything/ . A detailed discussion of this plug-in is beyond the scope of this article; however, sample applications are illustrated in the last section of this tutorial.
It is the objective of this article to explain how to sort WordPress search results by post title.
Basic Requirements and Enabling WordPress Search Widget
This tutorial has been tested to work in WordPress version 2.5.1 to 2.6.1. To tweak the WordPress search function appropriately, you need to have the following:
Full FTP access to your WordPress site.
A newer version of WordPress, specifically 2.5.1 to 2.7 (older versions of WordPress have not been tested for this application, and it is recommended that you upgrade for security reasons).
The tweak will not work if you do not have full FTP access and the appropriate version of WordPress. You may need to coordinate with your web agency or any person that has full access to the website server files.
If you have all of the requirements, the next thing you need to do is enable the WordPress Search Widget. The steps below have been tested to work in WordPress version 2.5.1 to 2.6.1.
1. Go to Dashboard
2. Go to Design
3. In the list of sub-menus, namely Themes, Widgets and Theme Editor, click “Widgets”
4. In the first column, you will see “Available Widgets.” Find “Search” and then click “Add.” This will add a search form to your website.
After completing these steps, the search widget will now be shown in the “current widgets” column. Check the screen shot below for an example: