Relevanssi includes a search form shortcode that can be used to display a search form. The shortcode is searchform and it was introduced in Relevanssi Premium 2.0 and Relevanssi 4.0.
Adding query parameters
This shortcode prints out a basic search form. If you want to add additional query parameters, that’s easy: just add parameters to the shortcode. Here are some examples:
will restrict the search form to just products.
will restrict the search form to posts, pages and news.
will restrict the search form to categories 10, 14 and 17.
will do a multisite search on blogs 1, 2 and 3.
Any parameter you add will be added to the search form directly as a hidden input field.
Adding dropdowns
The shortcode also supports adding dropdown selections for users. You can do dropdowns for post types and taxonomies.
will create a dropdown for post types in the index.
will create a dropdown for categories.
will create a dropdown for tags.
All other taxonomies are also possible. You can add multiple dropdowns by using different names for the attributes. As long as the attribute name begins with “dropdown”, it will create a dropdown in the form:
Checkboxes
You can also add checkbox lists for taxonomy terms and post types. This creates a checkbox list of categories for user to choose from:
If you want checkboxes for post types, use this:
You can also have some post types checked by default by prefixing them with asterisks:
Troubleshooting
This function uses the WordPress default search form (provided by get_search_form()). However, if your theme includes a search form (in the searchform.php file), the function will use that. That may cause unexpected results if your theme search form greatly deviates from the WP standard.
Modifying the search form
If you want to make changes to the search form, you can either use a searchform.php file in your theme to provide a custom search form or use the get_search_form filter function to edit the default search form as you wish. For example, if you want the “Search” button to say “Find”, you can change it like this:
add_filter( 'get_search_form', 'rlv_modify_search_form' );
function rlv_modify_search_form( $form ) {
$form = str_replace( 'value="Search"', 'value="Find"', $form );
return $form;
}Add this code to your site. Note this will then apply to all search forms, not just the ones generated by the shortcode. Versions 2.2.4 (Premium) and 4.1.3 (free) added a new filter hook, relevanssi_search_form, which does the same but only applies to the shortcode search form.