Search
Overview
Allow users to filter content by keyword(s).
Available options
Name | Description |
---|---|
Search engine | Which search engine to use (extra engines appear if SearchWP or our Relevanssi integration add-on is installed). |
Placeholder text | The placeholder text that appears within the input box (default: “Enter keywords”). Note: this text is translatable with the facetwp_i18n hook. The default text is also translatable with a translation plugin or a WordPress gettext filter (see this example). |
Auto refresh | Whether to automatically refresh the results while typing. |
What gets searched?
By default, Search facets use WP Core search, which is limited to searching the post title, excerpt, and post content, but nothing else. It also has no understanding of relevancy.
If you need more flexibility, we integrate with both SearchWP (built-in) and Relevanssi (with our add-on). Both plugins let you search other data (custom fields, taxonomy terms, PDF content, etc) too, and offer a lot of features to make search results more relevant. After installing, new choices will appear in the facet’s Search engine
setting.
Limit the number of results
By default, a Search facet returns a maximum of 200 results. This maximum can be changed by using the facetwp_search_query_args
hook to change the posts_per_page
query parameter:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_search_query_args', function( $search_args, $params ) { $search_args['posts_per_page'] = -1; // Show all search results return $search_args; }, 10, 2 );
Include draft posts
Similar to the previous example, you can force draft posts to appear in the search results by adding them to the post_status
query argument with the facetwp_search_query_args hook
:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_search_query_args', function( $search_args, $params ) { $search_args['post_status'] = [ 'publish', 'draft' ]; return $search_args; }, 10, 2 );
Exclude posts from search results
The same hook can be used to add a post__not_in
query argument to prevent certain posts from showing up in the search results:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_search_query_args', function( $search_args, $params ) { $search_args['post__not_in'] = [ 893,894 ]; // The post ID(s) to exclude from the search results return $search_args; }, 10, 2 );
Disable order by relevance
When a Search facet is in use, the results are automatically ordered by relevance (using 'orderby' => 'post__in'
). To disable this feature and restore the original order, add the following to your (child) theme’s functions.php:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_use_search_relevancy', '__return_false' );
Add a “Clear” button to a Search facet
Currently, Search facets do not have a “Clear” button or icon.
If you want to add a clear button/icon to a Search facet’s input box, check out our tutorial on how to accomplish that.
Search facets and WooCommerce Catalog visibility settings

If you have a Search facet on a template that queries WooCommerce products, and you are using the “Catalog visibility” settings to influence if products show up in the search results or not, be aware that these settings are ignored when using a Search facet.
If you need these settings to work for a Search facet results, read this guide.