Hi there,
I use Toolset for my Search Results Archive page.
I then have some filters where the user can narrow down their results.
The initial search uses the standard 's' WordPress parameter.
The Toolset search uses the 'wpv_post_search' parameter.
However, how can I add a text search that overwrites the initial search, so that the user can change their search term?
Thank you.
Ah, hold up. Perhaps the easier way to do this is to put in a generic WP search bar up top, with filters beneath. Thus the search will reset completely?
Unless there's a more recommended way of doing this?
Hi,
Thank you for contacting us and I'd be happy to assist.
Your observation is correct and the WordPress default text search uses the URL parameter "s" whereas the Toolset's text search uses the URL parameter "wpv_post_search".
The downside, of using the default text search on the Toolset controlled search page is that it will work independently from the other Toolset search filters.
A better approach would be to remove the default text search from the search page and use the Toolset's own search field, with the other search filters.
To copy the text search term from the URL parameter "s" to "wpv_post_search" you can use the filter "pre_get_posts":
( ref: https://developer.wordpress.org/reference/hooks/pre_get_posts/ )
function CustomSearchFilter_func($query)
{
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
$_GET['wpv_post_search'] = $_GET['s'];
}
}
return $query;
}
add_action('pre_get_posts', 'CustomSearchFilter_func');
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
As a result, when you'll perform a search using the default WordPress search, from anywhere on the website and reach the search page, the searched term will automatically be selected in the Toolset's text search field too.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar