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, <?php add_action('pre_get_posts','sort_searchresult_by_title'); function sort_searchresult_by_title($k) { if(is_search()) { $k->query_vars['orderby'] = 'title'; $k->query_vars['order'] = 'DESC'; } } ?> 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: $k->query_vars['order'] = 'DESC'; To download the plug-in, visit the following URL: http://blog.360.yahoo.com/blog-nNv5JKEydKKD9OmfLBfY?p=2
blog comments powered by Disqus |