searchwp\entry\data
4.0.0以降
\SearchWP\Entry をカスタマイズしてからインデックスを作成します。
パラメータ
| タイプ | パラメータ | デフォルト | 提供開始 |
|---|---|---|---|
| 配列 | $data |
Entry Source によって定義されたインデックス作成対象のデータ | 4.0.0 |
| \SearchWP\Entry | $entry |
Entry 自体 | 4.0.0 |
例
All hooks should be added to your custom SearchWP Customizations Plugin.
Entry に「追加」メタデータを追加する
「追加」の任意のデータをインデックス作成したい場合は、既存のソース属性を利用して行うことができます。この例では、「追加メタデータ」の概念を実装し、登録済みのすべての投稿タイプに既に存在するカスタムフィールド属性を使用してデータを保存できるようにします。
This file contains hidden or 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 ); |

