searchwp\entry\data
Since: 4.0.0
Table of Contents
Customize an \SearchWP\Entry
before it is indexed.
Parameters
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 |
Examples
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 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 ); |