wpfts_preset_detected (Filter)
The wpfts_preset_detected
filter in WP Fast Total Search allows developers to modify the preset used for the current search query. It’s called after the plugin has determined the preset based on the search type (e.g., admin search, frontend search, Gutenberg block search) and widget settings, but before the preset is applied.
When to Use
This filter is useful when you need to dynamically change the search preset based on specific conditions. For example:
- Changing the preset based on the current page: You can use this filter to apply different presets on different pages of your website.
- Changing the preset based on the user role: You can configure different search presets for different user roles.
- Changing the preset based on query parameters: You can change the preset based on the values passed in the search query.
Arguments
$preset_ident
(string): The preset identifier determined by the plugin. May be an empty string if no preset was determined.$wpq
(object): TheWP_Query
object containing the parameters of the current query.
Return Value
$preset_ident
(string): The preset identifier that will be used for the search.
Example (Changing the preset on a specific category page)
add_filter('wpfts_preset_detected', 'change_preset_for_category', 10, 2);
function change_preset_for_category($preset_ident, $wpq)
{
if (is_category('my-special-category')) {
return 'my_custom_preset';
}
return $preset_ident;
}
Important Notes
- The
wpfts_preset_detected
filter is called before the preset is applied. - If you return an empty string, the standard WordPress search will be used.
- Ensure that the preset whose identifier you are returning exists.
The wpfts_preset_detected
filter provides developers with a powerful mechanism for dynamically changing search settings in WP Fast Total Search, allowing you to adapt the search to different contexts and conditions.