Search Box Filters
The search box in Max Mega Menu Pro will use the standard WordPress search. It is possible to modify the behaviour of the search box using filters built into Max Mega Menu Pro.
Restricting results to WooCommerce Products
Update: Since publishing this article we have introduced a checkbox option to the Search Replacement and Search Toggle block to restrict search results to WooCommerce Products. The code below is no longer required.
If you are using the WooCommerce, the following code will alter the search box so that results are displayed using the WooCommerce search results template. This code should be added to your themes functions.php file:
1 2 3 4 |
function mmm_restrict_search_to_products($html) { return $html . "<input type='hidden' name='post_type' value='product' />"; } add_filter('megamenu_search_inputs', 'mmm_restrict_search_to_products'); |
Restricting results to Heroic Knowledge Base Articles
If you are using the Heroic Knowledge Base plugin, the following code will alter the search box so that search results are restricted Knowledge Base Articles. This code should be added to your themes functions.php file:
1 2 3 4 |
function mmm_add_ht_kb_search($html) { return $html . "<input type='hidden' name='ht-kb-search' value='1' />"; } add_filter('megamenu_search_inputs', 'mmm_add_ht_kb_search'); |
Changing the search variable from “?s=” to “?gsc=”
Max Mega Menu uses the default ‘s’ variable to perform the search. If you are using plugin that uses a different parameter you can use the filter below to change it. This code should be added to your themes functions.php file:
1 2 3 4 |
function mmm_search_var($var) { return 'gsc'; } add_filter('megamenu_search_var', 'mmm_search_var'); |
Changing the search path from “/?s=” to “/search/?s=”
Max Mega Menu uses the default root path to perform searches. If you are using a different page to display results you can use the filter below to change it. This code should be added to your themes functions.php file:
1 2 3 4 |
function mmm_search_action($action) { return $action . 'search/'; } add_filter('megamenu_search_action', 'mmm_search_action'); |