wpfts_start_search_type (Filter)

The wpfts_start_search_type filter in WP Fast Total Search allows developers to modify the search type determined by the plugin at the beginning of query processing. The search type is used to select the search settings preset that will be applied to the query.

When to Use

This filter can be useful if you need to dynamically change the search type based on specific conditions, such as:

  • Changing the search type depending on the current page: You can use this filter to apply different presets on different pages of your website.
  • Changing the search type depending on the user role: You can define different search types for different user roles.
  • Changing the search type depending on query parameters: You can change the search type based on data passed in the URL.

Arguments

  • $search_type (string): The search type defined by the plugin. Can take values wpmainsearch_admin, wpmainsearch_frontend, wpblockquery, or an empty string if the type is not defined.
  • $wpq (object): The WP_Query object containing the parameters of the current query.

Return Value

  • $search_type (string): The modified search type.

Example (Changing the search type on a specific post type page)

add_filter('wpfts_start_search_type', 'change_search_type_for_cpt', 10, 2);
 
function change_search_type_for_cpt($search_type, $wpq)
{
	if (is_singular('my_custom_post_type')) {
		return 'my_custom_search_type'; // Return the new search type.
	}
	return $search_type; // Return the original type in other cases.
 
}

Important Notes

  • The wpfts_start_search_type filter is called before the selection of the search settings preset.
  • Changing the search type will lead to the use of a different preset if it is defined for the new search type.
  • If you return an empty string as the search type, the plugin will use the standard WordPress search.

This filter gives developers flexibility in customizing the search in WP Fast Total Search and allows dynamically changing the settings preset depending on various conditions.