I am beginning to wonder how to sort search results in word press by post titles. There is a plugin below.
<?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';
}
}
?>
Readme/ Instructions:
1. Download the plugin here.
2. Upload to wp-content/plugins directory in wordpress

Хай, ребята, я раньше был у Вас на сайте, но забыл пароль, где его можна посмотреть?
Hi Maxim, sorry but I cannot understand Russian language. Can you translate it to English please? Thanks.
I would like to use this plugin but it is causing error message on my site (v.2.8.2) like this one:
Warning: Cannot modify header information – headers already sent by (output started at /home/XXXX/public_html/XXXX/blog/wp-content/plugins/sort-searchresult-by-title/Sort_SearchResult_by_Title.php:21) in /home/XXXX/public_html/XXXX/blog/wp-includes/pluggable.php on line 865
Any ideas? Thanks!
Hi John,
Thanks for the feedback, I have now fixed this problem . Can you please remove the old version and download the version 2 (which is working for WP2.8.2)
This is the link: Download Version 2 of the WordPress Sort search result by Title.
Hi I was wondering how you would alter the code to use custom fields like price. I tried to simply change title to price in the php file however it didnt work. Any Suggestions are greatly appreciated.
Thanks, Mike !