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 default text that appears within the search input. Note: this text is translatable with the facetwp_i18n hook. |
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. Override via the following hook:
add_filter( 'facetwp_search_query_args', function( $search_args, $params ) {
$search_args['posts_per_page'] = -1;
return $search_args;
}, 10, 2 );
Include draft posts
Similar to the previous example, you can force drafts to appear in search results via the following hook:
add_filter( 'facetwp_search_query_args', function( $search_args, $params ) {
$search_args['post_status'] = [ 'publish', 'draft' ];
return $search_args;
}, 10, 2 );
Disable order by relevancy
With a search facet is in use, the results are automatically ordered by relevancy. To disable this feature, add the following code:
add_filter( 'facetwp_use_search_relevancy', '__return_false' );