Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active May 1, 2021 09:39
Embed
What would you like to do?
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