SearchWP

This Documentation is for SearchWP Version 3

Available since: 3.0

searchwp_stopwords

View Parameters »

Note: Use of this hook will require a manual reindex

Note: Until version 3.0 this hook was tagged searchwp_common_words (now deprecated)

By default, SearchWP excludes a list of words it considers to be too common to be useful in searches. These terms are called stopwords, and by excluding them SearchWP is able to reduce the overall size of the search index without compromising the quality of the index and improving performance.

Example: To remove a select number of default stopwords, add something like the following to your active theme’s functions.php:

<?php
function my_searchwp_stopwords( $terms ) {
// we DO NOT want to ignore 'first' so remove it from the list of common words
$words_to_keep = array( 'first' );
$terms = array_diff( $terms, $words_to_keep );
return $terms;
}
add_filter( 'searchwp_stopwords', 'my_searchwp_stopwords' );
view raw functions.php hosted with ❤ by GitHub

Example: To add your own stopwords, add the following to your active theme’s functions.php:

<?php
function my_searchwp_stopwords( $terms ) {
// add 'lorem', 'ipsum', and 'dolor' to SearchWP's default terms
$terms[] = 'lorem';
$terms[] = 'ipsum';
$terms[] = 'dolor';
return $terms;
}
add_filter( 'searchwp_stopwords', 'my_searchwp_stopwords' );
view raw gistfile1.php hosted with ❤ by GitHub

Example: To completely replace stopwords with your own, add the following to your active theme’s functions.php:

<?php
function my_searchwp_stopwords( $terms ) {
// replace the default SearchWP default common words with 'lorem', 'ipsum', and 'dolor' ONLY
$terms = array( 'lorem', 'ipsum', 'dolor' );
return $terms;
}
add_filter( 'searchwp_stopwords', 'my_searchwp_stopwords' );
view raw gistfile1.php hosted with ❤ by GitHub

Example: To disable this feature entirely, return an empty array of stopwords and SearchWP will exclude nothing. You can do that by adding this snippet to your theme’s functions.php:

<?php
function my_searchwp_stopwords( $terms ) {
// do not exclude any words from the index
return array();
}
add_filter( 'searchwp_stopwords', 'my_searchwp_stopwords' );
view raw functions.php hosted with ❤ by GitHub

Parameters

Parameter Type Description
$stopwords Array

The default terms SearchWP considers to be stopwords