Note: You are viewing the documentation for Version 4View Version 3 Docs

searchwp\synonyms

Since: 4.0.0

Table of Contents

SearchWP uses Synonyms to both optimize the index and increase relevancy of search results.

The primary method of customizing the list of Synonyms is by way of the Settings tab of the SearchWP Settings screen. You can however programmatically filter Synonyms as well.

Parameters

Type Parameter Default Since
Array $synonyms
Key Type Value
sources String Search term(s)
synonyms String Synonym(s) for search term(s)
replace Boolean Whether synonym(s) should replace search term(s)
4.0.0
Array $args
Key Type Value
search_string String Submitted search string
query \SearchWP\Query The Query taking place
4.0.0

Examples

All hooks should be added to your custom SearchWP Customizations Plugin.

Add Synonym to existing Synonyms

Append a custom Synonym to the UI-defined set of Synonyms on the Settings tab of the SearchWP Settings screen

<?php
// Add Synonym to existing Synonyms in SearchWP.
add_filter( 'searchwp\synonyms', function( $synonyms, $args ) {
$synonyms[] = [
'sources' => 'seo',
'synonyms' => 'search engine optimization',
'replace' => false,
];
return $synonyms;
}, 20, 2 );

How to use this code

Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP