Since: 4.0.0

Table of Contents

Customize an \SearchWP\Entry before it is indexed.


Type Parameter Default Since
Array $data Data to index as defined by the Entry Source 4.0.0
\SearchWP\Entry $entry The Entry itself 4.0.0


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

Add 'extra' metadata to an Entry

If you would like to index ‘extra’ arbitrary data you can do so by utilizing existing Source Attributes. In this example we’ll implement a concept of ‘extra metadata’ that allows us to store data using the Custom Fields Attribute that already exists for all registered post types.

// Customize a SearchWP Entry before it is indexed.
add_filter( 'searchwp\entry\data', function( $data, $entry ) {
// Use this key when adding a Custom Field Attribute.
$extra_meta_key = 'my_extra_meta';
$value = 'This is extra data to index as extra meta';
// SearchWP's Post Meta Attribute expects that data is made of Tokens.
$data['meta'][ $extra_meta_key ] = new \SearchWP\Tokens( $value );
return $data;
}, 20, 2 );

How to use this code