Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active May 1, 2021 09:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/035bb07329c1518981db0c532dbe0576 to your computer and use it in GitHub Desktop.
Save jchristopher/035bb07329c1518981db0c532dbe0576 to your computer and use it in GitHub Desktop.
Change the WordPress search query parameter from 's' to something else
<?php
add_filter('init', function(){
global $wp;
$wp->add_query_var( 'search_query' );
$wp->remove_query_var( 's' );
} );
add_filter( 'request', function( $request ){
if ( isset( $_REQUEST['search_query'] ) ){
$request['s'] = $_REQUEST['search_query'];
}
return $request;
} );
@gianghl1983
Copy link

Hi,

I am trying to do without SearchWP (same purpose to change 's' to something else with this code snippet but it doesn't work)

Could you please help me!

Thanks!

@JakeGonzales
Copy link

Hi,

I am trying to do without SearchWP (same purpose to change 's' to something else with this code snippet but it doesn't work)

Could you please help me!

Thanks!

You might try this instead https://www.wpbeginner.com/wp-tutorials/how-to-change-the-default-search-url-slug-in-wordpress/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment