HomePHP Page 4 - Customizing WordPress Search Results to Sort by Title
Sort Search Results by Title Plug-in - PHP
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.
Sometimes it is easier not to edit the WordPress core files such as query.php, and just use WordPress plug-in features for this. This is a more convenient approach, since we only need to upload a PHP file to a /wp-content/plugins/ directory in your FTP server. Then activate the plug-in to enable the feature.
To do this, we need a PHP file. Below is the source code,
This plug-in works by adding actions (from the plug-in) to WordPress's existing search functions. This is indicated by add_action
The PHP function sort_searchresult_by_title($k) will perform the actual sorting. This will communicate with WordPress's MySQL database to pick up post titles and then sort them by “descending” order as specified by: