Better Search Pro enhances the WordPress REST API search results to show posts ordered by relevance. When you enable this feature, a REST API search is performed, and Better Search Pro applies the default search configuration, just as it does for standard WordPress search requests.

WordPress core utilises the REST API in various scenarios, including the ‘Add Link’ modal when searching for content. If you’ve customised Better Search settings to use specific configurations for admin searches, those settings will be applied in these cases as well. Depending on your search setup, this may result in unexpected behaviour.

Enable REST API support

You can enable this by navigating to the plugin settings page under Better Search > Settings. Enable ‘Enable REST API’ and save the settings. Alternatively, you can pass better_search_query as the parameter to enable relevance searching.

Better Search REST API Parameters

ParameterDescription
better_search_queryEnables Better Search for the REST API query when set to true.
search_excerptIncludes post excerpts in the search query.
search_taxonomiesSearches within taxonomy terms (e.g., categories or tags).
search_metaSearches within custom post meta fields.
search_authorsEnables searching by author names.
search_commentsIncludes post comments in the search query.
search_slugEnables searching within the post slug.
exclude_protected_postsExcludes password-protected posts from the search results.
exclude_post_idsA list of post IDs to exclude from the search results.
exclude_categoriesA list of category IDs to exclude posts from those categories in the results.
weight_titleSets the weight for matching keywords in post titles.
weight_contentSets the weight for matching keywords in post content.
min_relevanceFilters results to only include those with a relevance score equal to or greater than this value.

Notes:

  • All parameters are optional. If not provided, Better Search will use its default configuration.
  • You can use these parameters to fine-tune search behaviour for specific REST API requests.

Leave a Reply

Your email address will not be published. Required fields are marked *