Changing Search Query Parameter in WordPress
You may wonder why some would do such thing? Well, most obvious case is integration with existing website. Some times "s" parameter is already used and/or required to have function different from search. This where you have to alter default behavior of WordPress.
Future ProblemsFirst let's look at drawbacks. Apart from altering structure of well functioning application, the biggest problem that will rise in future will be updates. Every time new update is out, you would have to repeat this procedure and then merge new code into production environment.
StepsNonetheless we have to do it, so let's get started.
Step 1: SetupFirstly, you would need software that allows to search and replace on entire application folder. Most obvious example for Windows would be Aptana. If you have good software examples for other OSs, be sure to share it in comments.
Step 2: Search/ReplaceNow it is time to search and replace most obvious cases: $_GET['s'], $_REQUEST['s'], and $_POST['s']. I have to note that last one happens only once or twice, so you may want to hit later. You can go ahead and replace those with $_GET['search'], $_REQUEST['search'], and $_POST['search'] accordingly.
Step 3: Search/Replace MoreAs you probably guessed getting parameter form request is not the only case where you may need to alter WordPress's code. Second thing to look for is 's'. You will see that number of results will be much greater than you expected. Now it is important to pay attention. Searching for 's' will return files that have nothing to do with search functionality. Most of JS code has nothing to do with search, so you can skip it for now. Look at PHP files that lay in wp-includes and wp-admin folders, but keep mind that some times 's' may mean seconds in time formating of just be appended to the end of word.
$edit_others_cap = 'edit_others_' . $post_type_cap . 's'; $read_private_cap = 'read_private_' . $post_type_cap . 's';
Step 4: Forget about ?s=Inside wp-includesclasses.php you'll find that $public_query_vars keeps records of common query variables, so need to tell WordPress to forget ?s.
var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
document.getElementById('s') && document.getElementById('s').focus();becomes:
document.getElementById('search') && document.getElementById('search').focus();