This Documentation is for SearchWP Version 3

Available since: 2.9


View Parameters »

Note: Use of this hook will require a manual reindex

SearchWP will actively exclude content from the index if you use any Limit To or Exclude rules in your engine settings. Using this hook you can filter what’s been excluded by those rules during indexing (e.g. to allow excluded content to be indexed)

When is that useful?

It sounds counterintuitive to ignore engine rules when indexing (which will index content that’s ultimately excluded by engine rules anyway) but SearchWP allows for customizations that can make engine rules dynamic. There may be a case where you want content excluded in most but not all cases.

Example: let’s say you want to exclude a Category from search results for regular visitors, but allow logged-in visitors to see everything. You can set up your engine to Exclude the Category, but use this hook to make sure the indexer indexes everything by adding this to your theme’s functions.php:

// By default SearchWP will exclude content that's excluded by the engine configuration
// This hook filters what has been excluded (i.e. breaks the rules!)
// See example context at
add_filter( 'searchwp_indexer_excluded_by_rules', function( $excluded_ids ) {
// Always index everything
return array();
} );
view raw functions.php hosted with ❤ by GitHub

To finalize the implementation you would also need to ensure that the exclusion is not applied when searching as well, which can be done with this hook:

// Do not exclude anything if user is logged in
add_filter( 'searchwp_exclude', function( $excluded_ids, $engine, $terms ) {
return is_user_logged_in() ? array() : $excluded_ids;
}, 99, 3 );
view raw functions.php hosted with ❤ by GitHub


Parameter Type Description
$excluded_ids Array

The IDs that will be excluded from the index based on engine rules